Exemplo n.º 1
0
        void UpdateUserTrackingMode()
        {
            MyLocationConfiguration.LocationMode mode;

            switch (Map.UserTrackingMode)
            {
            default:
            case UserTrackingMode.None:
                mode = MyLocationConfiguration.LocationMode.Normal;
                break;

            case UserTrackingMode.Follow:
                mode = MyLocationConfiguration.LocationMode.Following;
                break;

            case UserTrackingMode.FollowWithCompass:
                mode = MyLocationConfiguration.LocationMode.Compass;
                break;
            }

            NativeMap.Map.SetMyLocationConfigeration(
                new MyLocationConfiguration(mode, true, null)
                );

            if (UserTrackingMode.FollowWithCompass != Map.UserTrackingMode)
            {
                // 恢复俯视角
                MapStatusUpdate overlook = MapStatusUpdateFactory.NewMapStatus(
                    new MapStatus.Builder(NativeMap.Map.MapStatus).Rotate(0).Overlook(0).Build()
                    );

                NativeMap.Map.AnimateMapStatus(overlook);
            }
        }
Exemplo n.º 2
0
        private void UpdateUserTrackingMode()
        {
            if (Map != null)
            {
                var mode = Map.UserTrackingMode switch
                {
                    UserTrackingMode.Follow => MyLocationConfiguration.LocationMode.Following,
                    UserTrackingMode.FollowWithCompass => MyLocationConfiguration.LocationMode.Compass,
                    _ => MyLocationConfiguration.LocationMode.Normal,
                };

                if (NativeMap.Map != null)
                {
                    NativeMap.Map.SetMyLocationConfiguration(new MyLocationConfiguration(mode, true, null));
                }

                if (UserTrackingMode.FollowWithCompass != Map.UserTrackingMode)
                {
                    // 恢复俯视角
                    MapStatusUpdate overlook = MapStatusUpdateFactory.NewMapStatus(
                        new MapStatus.Builder(NativeMap.Map.MapStatus).Rotate(0).Overlook(0).Build()
                        );
                    if (NativeMap.Map != null)
                    {
                        NativeMap.Map.AnimateMapStatus(overlook);
                    }
                }
            }
        }
        void IBDLocationListener.OnReceiveLocation(BDLocation location)
        {
            if (location == null)
            {
                return;
            }
            //Resolver.Resolve<IUserDialogService> ().Alert ("receive dialog");
            MyLocationData locData = new MyLocationData.Builder()
                                     .Accuracy(location.Radius)
                                     // 此处设置开发者获取到的方向信息,顺时针0-360
                                     .Direction(100).Latitude(location.Latitude)
                                     .Longitude(location.Longitude).Build();

            mBaiduMap.SetMyLocationData(locData);
            LatLng cenpt = new LatLng(location.Latitude, location.Longitude);
            //定义地图状态
            MapStatus mMapStatus = new MapStatus.Builder()
                                   .Target(cenpt)
                                   .Zoom(14)
                                   .Build();
            //定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
            //
            MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.NewMapStatus(mMapStatus);

            //改变地图状态
            mBaiduMap.SetMapStatus(mMapStatusUpdate);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 移动位置
        /// </summary>
        /// <param name="coordinate"></param>
        public void AnimateTo(Coordinate coordinate)
        {
            this.mapView.Map.Clear();

            var point = new LatLng(coordinate.Latitude, coordinate.Longitude);

            //Title="雪花啤酒(西安)分公司",Lat=34.364438,Lng=108.941338
            //创建当前位置Marker图标
            BitmapDescriptor bitmap = BitmapDescriptorFactory.FromResource(Resource.Drawable.red_location);
            //构建MarkerOption,用于在地图上添加Marker
            OverlayOptions option = new MarkerOptions()
                                    .InvokePosition(point)
                                    .Anchor(0.5f, 0.5f)
                                    .ScaleX(0.5f)
                                    .ScaleY(0.5f)
                                    .Draggable(true)
                                    .InvokeIcon(bitmap);

            ////在地图上添加Marker,并显示
            this.mapView.Map.AddOverlay(option);


            //使地图移动到当前位置
            MapStatus mMapStatus = new MapStatus.Builder()
                                   .Target(point)
                                   .Zoom(18)
                                   .Build();

            //定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
            MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.NewMapStatus(mMapStatus);

            //改变地图状态
            this.mapView.Map.SetMapStatus(mMapStatusUpdate);
        }
Exemplo n.º 5
0
        public void Refresh(List <Option> points)
        {
            this.mapView.Map.Clear();
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            foreach (var point in points)
            {
                var latLng = new LatLng(point.Lat, point.Lng);
                builder = builder.Include(latLng);
                BitmapDescriptor bitmap = BitmapDescriptorFactory.FromResource(Resource.Drawable.red_location);
                //构建MarkerOption,用于在地图上添加Marker
                OverlayOptions option = new MarkerOptions()
                                        .InvokePosition(latLng)
                                        .InvokeTitle(point.Title)
                                        .Anchor(0.5f, 0.5f)
                                        .Draggable(true)
                                        .ScaleX(0.5f)
                                        .ScaleY(0.5f)
                                        .InvokeIcon(bitmap);

                ////在地图上添加Marker,并显示
                this.mapView.Map.AddOverlay(option);
            }

            LatLngBounds    latlngBounds = builder.Build();
            MapStatusUpdate u            = MapStatusUpdateFactory.NewLatLngBounds(latlngBounds, mapView.Width, mapView.Height);

            mapView.Map.AnimateMapStatus(u);
        }
Exemplo n.º 6
0
 private void UpdateCenter()
 {
     if (NativeMap.Map != null)
     {
         var locData = new MyLocationData.Builder().Latitude(Map.Center.Latitude).Longitude(Map.Center.Longitude).Build();
         NativeMap.Map.AnimateMapStatus(MapStatusUpdateFactory.NewLatLng(Map.Center.ToNative()));
         NativeMap.Map.SetMyLocationData(locData);
     }
 }
Exemplo n.º 7
0
 private void UpdateZoomLevel()
 {
     if (NativeMap.Map != null)
     {
         NativeMap.Map.AnimateMapStatus(
             MapStatusUpdateFactory.ZoomTo(Map.ZoomLevel)
             );
     }
 }
Exemplo n.º 8
0
        private void InitView()
        {
            //设置标题栏

            var img_header_back = FindViewById <ImageView> (Resource.Id.img_header_back);

            img_header_back.Click += (sender, e) =>
            {
                this.Finish();
                OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
            };
            var bundle        = Intent.Extras;
            var alarmPosition = bundle.GetString("alarmPosition");

            if (!string.IsNullOrEmpty(alarmPosition) && alarmPosition.Contains(","))
            {
                var Positions = alarmPosition.Split(new char[] { ',' });
                nPosition = Convert.ToDouble(Positions [0].Substring(1));
                ePosition = Convert.ToDouble(Positions [1].Substring(1));
            }

            var tv_back = FindViewById <TextView> (Resource.Id.tv_back);

            tv_back.Text = "报警详细";
            var tv_desc = FindViewById <TextView> (Resource.Id.tv_desc);

            tv_desc.Text = "报警位置显示";

            mMapView      = FindViewById <MapView> (Resource.Id.bmap_view);
            bdMap         = mMapView.Map;
            bdMap.MapType = BaiduMap.MapTypeNormal;
            LatLng sourceLatLng = new LatLng(nPosition, ePosition);
            // 将GPS设备采集的原始GPS坐标转换成百度坐标
            CoordinateConverter converter = new CoordinateConverter();

            converter.From(Com.Baidu.Mapapi.Utils.CoordinateConverter.CoordType.Gps);
            // sourceLatLng待转换坐标
            converter.Coord(sourceLatLng);
            LatLng desLatLng = converter.Convert();
            //构建MarkerOption,用于在地图上添加Marker
            //构建Marker图标
            BitmapDescriptor bitmap = BitmapDescriptorFactory
                                      .FromResource(Resource.Drawable.ic_map);
            OverlayOptions option = new MarkerOptions().InvokePosition(desLatLng).InvokeIcon(bitmap).Draggable(true).InvokeZIndex(9);

            //在地图上添加Marker,并显示
            bdMap.AddOverlay(option);
            // 将地图移动到覆盖物位置
            MapStatusUpdate u = MapStatusUpdateFactory.NewLatLng(desLatLng);

            bdMap.SetMapStatus(u);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 缩放地图,使所有Overlay都在合适的视野内
        /// 注: 该方法只对Marker类型的overlay有效
        /// </summary>
        public void ZoomToSpan()
        {
            ////获取地图可视区域
            //var bounds = map.GetBounds();
            ////获取西南角的经纬度(左下端点)
            //var sw = bounds.getSouthWest();
            ////获取东北角的经纬度(右上端点)
            //var ne = bounds.getNorthEast();
            ////获取西北角的经纬度(左上端点)
            //var wn = new BMap.Point(sw.lng, ne.lat);
            ////获取东南角的经纬度(右下端点)
            //var es = new BMap.Point(ne.lng, sw.lat);


            if (NativeMap.Map == null)
            {
                return;
            }
            var mOverlayList = Map.Pins;

            if (mOverlayList.Count > 0)
            {
                LatLngBounds.Builder builder = new LatLngBounds.Builder();
                foreach (var item in mOverlayList)
                {
                    // polyline 中的点可能太多,只按marker 缩放
                    var overlay = (Marker)item?.NativeObject;
                    if (overlay != null)
                    {
                        builder.Include(((Marker)overlay).Position);
                    }
                }

                MapStatus mapStatus = NativeMap.Map.MapStatus;
                if (null != mapStatus)
                {
                    int width  = mapStatus.WinRound.Right - NativeMap.Map.MapStatus.WinRound.Left - 400;
                    int height = mapStatus.WinRound.Bottom - NativeMap.Map.MapStatus.WinRound.Top - 400;
                    NativeMap.Map.SetMapStatus(MapStatusUpdateFactory.NewLatLngBounds(builder.Build(), width, height));
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 设置显示在规定宽高中的地图地理范围
        /// </summary>
        /// <param name="paddingLeft"></param>
        /// <param name="paddingTop"></param>
        /// <param name="paddingRight"></param>
        /// <param name="paddingBottom"></param>
        public void ZoomToSpanPaddingBounds(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom)
        {
            if (NativeMap.Map == null)
            {
                return;
            }
            var mOverlayList = Map.Pins;

            if (mOverlayList.Count > 0)
            {
                LatLngBounds.Builder builder = new LatLngBounds.Builder();
                foreach (var item in mOverlayList)
                {
                    // polyline 中的点可能太多,只按marker 缩放
                    var overlay = (Marker)item?.NativeObject;
                    if (overlay != null)
                    {
                        builder.Include(((Marker)overlay).Position);
                    }
                }
                NativeMap.Map.SetMapStatus(MapStatusUpdateFactory
                                           .NewLatLngBounds(builder.Build(), paddingLeft, paddingTop, paddingRight, paddingBottom));
            }
        }
Exemplo n.º 11
0
 void UpdateCenter()
 {
     NativeMap.Map.AnimateMapStatus(
         MapStatusUpdateFactory.NewLatLng(Map.Center.ToNative())
         );
 }
Exemplo n.º 12
0
 void UpdateZoomLevel()
 {
     NativeMap.Map.AnimateMapStatus(
         MapStatusUpdateFactory.ZoomTo(Map.ZoomLevel)
         );
 }
Exemplo n.º 13
0
 void UpdateZoomLevel()
 {
     mapView.Map.AnimateMapStatus(
         MapStatusUpdateFactory.ZoomTo(Map.ZoomLevel)
         );
 }