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); } }
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); }
/// <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); }
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); }
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); }