private void Button_DrawCircle_Click(object sender, RoutedEventArgs e) { circle = amap.AddCircle(new AMapCircleOptions() { Center = amap.Center, Radius = 2000, }); this.btnVisible.IsEnabled = true; }
private async void TrackLocationClick(object sender, RoutedEventArgs e) { MessageDialog messageDialog = new MessageDialog("启动tracking"); await messageDialog.ShowAsync(); trackingGeolocator = new AMapGeolocator(); trackingGeolocator.PositionChanged += aMapGeolocator_PositionChanged; //模拟器不能获取经纬度 var currentLocation = await trackingGeolocator.GetLngLatAsync(); if (trackingIcon == null) { trackingIcon = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/marker_gps_no_sharing.png", UriKind.RelativeOrAbsolute)), Location = currentLocation, NormalizedAnchorPoint = new Point(0.5, 0.5) }; } if (amapcircle == null) { amapcircle = new AMapCircle { FillColor = Color.FromArgb(80, 100, 150, 255), StrokeThickness = 2, StrokeColor = Color.FromArgb(80, 0, 0, 255), Center = currentLocation, Radius = 500 }; } bool circleContained = baseLayer.OverLays.Contains(amapcircle); bool trackingIconContained = baseLayer.OverLays.Contains(trackingIcon); if (!trackingIconContained) { baseLayer.Add(trackingIcon); } if (!circleContained) { baseLayer.Add(amapcircle); } aMapControl.TrySetViewAsync(currentLocation, 15, null, null, AMapAnimationKind.Default); trackingGeolocator.Start(); }
private void Button_DrawCircle_Click(object sender, RoutedEventArgs e) { //绘圆 circle = amap.AddCircle(new AMapCircleOptions() { Center = amap.Center, //圆点位置 Radius = 1000, //半径 FillColor = Color.FromArgb(70, 100, 150, 255), StrokeWidth = 3, StrokeColor = Color.FromArgb(255, 0, 0, 255) }); }
private void Circle_Click(object sender, RoutedEventArgs e) { Color c = new Color { R = 0, G = 0, B = 255, A = 255 / 2 }; circle = new AMapCircle { Center = aMapControl.Center, FillColor = c, Radius = 5000, StrokeColor = Colors.Red, StrokeThickness = 5 }; baseLayer.Add(circle); }
void amap_Loaded(object sender, RoutedEventArgs e) { this.Dispatcher.BeginInvoke(() => { amap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(amap.Center, 12)); List <LatLng> lnglats = new List <LatLng>(); lnglats.Add(new LatLng(amap.Center.latitude + 0.03, amap.Center.longitude + 0.04)); lnglats.Add(new LatLng(amap.Center.latitude - 0.03, amap.Center.longitude - 0.04)); //绘圆 circle = mapLayer.AddCircle(new AMapCircleOptions() { Center = amap.Center, Radius = 2000, FillColor = Color.FromArgb(80, 0, 0, 255), ZIndex = 5, }); //绘线 polyline = mapLayer.AddPolyline(new AMapPolylineOptions() { Points = lnglats, Width = 5, Color = Color.FromArgb(255, 255, 0, 0), ZIndex = 8, }); marker1 = mapLayer.AddMarker(new AMapMarkerOptions() { Position = amap.Center, Title = "Title", Snippet = "Snippet", IconUri = new Uri("Images/AZURE.png", UriKind.Relative), }); marker2 = mapLayer.AddMarker(new AMapMarkerOptions() { Position = amap.Center, Title = "Title", Snippet = "Snippet", IconUri = new Uri("Images/RED.png", UriKind.Relative), Anchor = new Point(1, 1), }); }); }
void mylocation_PositionChanged(AMapGeolocator sender, AMapPositionChangedEventArgs args) { this.Dispatcher.BeginInvoke(() => { if (marker == null) { //添加圆 circle = amap.AddCircle(new AMapCircleOptions() { Center = args.LngLat, //圆点位置 Radius = (float)args.Accuracy, //半径 FillColor = Color.FromArgb(80, 100, 150, 255), StrokeWidth = 2, //边框粗细 StrokeColor = Color.FromArgb(80, 0, 0, 255), //边框颜色 }); //添加点标注,用于标注地图上的点 marker = amap.AddMarker( new AMapMarkerOptions() { Position = args.LngLat, //图标的位置 Title = "我的位置", IconUri = new Uri("Images/marker_gps_no_sharing.png", UriKind.Relative), //图标的URL Anchor = new Point(0.5, 0.5), //图标中心点 }); } else { //点标注和圆的位置在当前经纬度 marker.Position = args.LngLat; circle.Center = args.LngLat; circle.Radius = (float)args.Accuracy;//圆半径 } //设置当前地图的经纬度和缩放级别 amap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(args.LngLat, 15)); Debug.WriteLine("定位精度:" + args.Accuracy + "米"); Debug.WriteLine("定位经纬度:" + args.LngLat); }); }
private void AddToMap() { //添加圆 m_circle = m_amap.AddCircle(new AMapCircleOptions() { Center = m_args.LngLat,//圆点位置 Radius = (float)m_args.Accuracy,//半径 FillColor = Color.FromArgb(80, 100, 150, 255), StrokeWidth = 2,//边框粗细 StrokeColor = Color.FromArgb(80, 0, 0, 255),//边框颜色 }); //添加点标注,用于标注地图上的点 m_marker = m_amap.AddMarker( new AMapMarkerOptions() { Position = m_args.LngLat,//图标的位置 Title = "我的位置", Snippet = m_args.LngLat.ToString(), IconUri = new Uri("./Assets/Images/marker_gps_no_sharing.png", UriKind.Relative),//图标的URL Anchor = new Point(0.5, 0.5),//图标中心点 }); foreach (Station stat in m_nearbyStats) { AMapMarkerOptions opt = new AMapMarkerOptions() { Position = new LatLng(stat.Latitude,stat.Longitude), Title = stat.StationName, Snippet = stat.StationName, IconUri = new Uri("./Assets/Images/BLUE.png", UriKind.Relative), }; m_amap.AddMarker(opt); } //设置当前地图的经纬度和缩放级别 m_amap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(m_args.LngLat, 15)); }
/// <summary> /// 监听位置变化 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnPositionChanged(AMapGeolocator sender, AMapPositionChangedEventArgs args) { Debug.WriteLine("OnPositionChanged"); Dispatcher.BeginInvoke(() => { if (currentLocationMarker == null) { //添加定位精度圈,为覆盖物中的圆 currentLocationCircle = map.AddCircle(new AMapCircleOptions { Center = args.LngLat, //圆点位置 Radius = (float)args.Accuracy, //半径 FillColor = Color.FromArgb(80, 100, 150, 255), StrokeWidth = 2, //边框粗细 StrokeColor = Color.FromArgb(80, 0, 0, 255) //边框颜色 }); currentLocationMarker = map.AddMarker(new AMapMarkerOptions { Position = args.LngLat, //图标的位置 Title = "我的位置", IconUri = new Uri("Images/current_location.png", UriKind.Relative), //图标的URL //Anchor = new Point(0.5, 0.5) //图标中心点 }); } else { //更新当前位置 currentLocationMarker.Position = args.LngLat; currentLocationCircle.Center = args.LngLat; currentLocationCircle.Radius = (float)args.Accuracy; } //设置当前地图的经纬度和缩放级别 map.MoveCamera(CameraUpdateFactory.NewLatLngZoom(args.LngLat, 15)); Debug.WriteLine("定位精度:{0}米", args.Accuracy); Debug.WriteLine("定位经纬度:{0}", args.LngLat); }); }
private bool _isNew;//屏蔽大北京 // 构造函数 public MainPage() { InitializeComponent(); /******变量初始化*****/ _zoomIsNew = true; _cameraIsNew = true; _isNew = true; isExit = false; _client = (Application.Current as App).SocketClient; /******变量初始化*****/ _amap = (Application.Current as App).TempMap; if (_amap == null) { _amap=new AMap();//新建地图 } if (_amap != null) { ContentPanel.Children.Add(_amap); //加载地图 //恢复地图相关参数 #region _latlng = (Application.Current as App)._latlng; _bearing = (Application.Current as App)._bearing; _tile = (Application.Current as App)._tile; _circle = (Application.Current as App)._circle; _locationMarker = (Application.Current as App)._locationMarker; _cameraLatlng = (Application.Current as App)._CameraLatLng; _mapZoom = (Application.Current as App)._mapZoom; _cameraIsNew = (Application.Current as App)._cameraIsNew; _isNew = (Application.Current as App)._isNew; #endregion DoubleTabToExit(2);//按两次退出键退出程序 //异步连接服务器,增加程序友好性 Dispatcher.BeginInvoke(() => { Debug.WriteLine("连接服务器"); ConnectServer(_client); } ); } var uiset = _amap.GetUiSettings(); uiset.CompassControlEnabled = false; //将原有指南针设置为不显示 uiset.ZoomControlsEnabled = false; //将原有缩放控件设置为不显示 MakerTextBlock.Visibility = Visibility.Collapsed;//设置标记信息文本框不可见 MakertextblockbgGrid.Visibility = Visibility.Collapsed;//设置标记信息文本框背景不可见 BuildLocalizedApplicationBar();// 用于本地化 ApplicationBar 的示例代码 //ApplicationBar.IsVisible = false; _amap.CameraChangeListener += amap_CameraChangeListener; //视角移动函数(指南针使用) _amap.Tap += amap_Tap;//添加地图单击事件函数 _amap.Hold += amap_hold;//添加地图长按事件函数 Loaded += Mylocation_Loaded; Unloaded += Mylocation_Unloaded; }
/// <summary> /// 用户位置改变后marker绘制函数 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void mylocation_PositionChanged(AMapGeolocator sender, AMapPositionChangedEventArgs args) { _latlng = args.LngLat;//系统定位经纬度 _amap.Dispatcher.BeginInvoke(() => { //GeoSearch(args.LngLat); if (_locationMarker == null) { //添加圆 _circle = _amap.AddCircle(new AMapCircleOptions { Center = args.LngLat, //圆点位置 Radius = (float)20, //半径 FillColor = Color.FromArgb(80, 100, 150, 255),//圆的填充颜色 StrokeWidth = 1, //边框粗细 StrokeColor = Color.FromArgb(80, 100, 150, 255) //圆的边框颜色 }); //添加点标注,用于标注地图上的点 _locationMarker = _amap.AddMarker(new AMapMarkerOptions { Position = args.LngLat, //图标的位置 //待修改,更换IconUri的图标// IconUri = new Uri("Images/myLocationIcon.png", UriKind.RelativeOrAbsolute), //图标的URL Anchor = new Point(0.5, 0.5) //图标中心点 }); } else { //点标注和圆的位置在当前经纬度 _locationMarker.Position = args.LngLat; _circle.Center = args.LngLat; _circle.Radius = (float)20; //圆半径 } //设置当前地图的经纬度和缩放级别 if (_cameraIsNew) { if (_mapZoom == 0) _mapZoom = 17; _amap.AnimateCamera(CameraUpdateFactory.NewCameraPosition(_latlng, _mapZoom, _bearing, _tile), 2);//移动视角(动画效果) _cameraIsNew = false; } Debug.WriteLine("定位精度:" + args.Accuracy + "米"); Debug.WriteLine("定位经纬度:" + args.LngLat); }); AMapReGeoCodeResult currentLocationResult;//用户实时位置AMapReGeoCodeResult currentLocationResult = await AMapReGeoCodeSearch.GeoCodeToAddress(_latlng.longitude, _latlng.latitude, 50, "", Extensions.All); Dispatcher.BeginInvoke(() => { if (currentLocationResult.Erro == null && currentLocationResult.ReGeoCode != null) { AMapReGeoCode regeocode = currentLocationResult.ReGeoCode; MakerTextBlock.Text = regeocode.Formatted_address; Debug.WriteLine("道路信息"); foreach (var temp in regeocode.Roadslist) { Debug.WriteLine(temp.Id); _client.SendLocation(temp.Id,temp.Name, args.LngLat.latitude.ToString(CultureInfo.InvariantCulture), args.LngLat.longitude.ToString(CultureInfo.InvariantCulture)); break; } } } ); }
/// <summary> /// 获取用户位置后,触发本函数 /// </summary> /// <param name="asyncInfo"></param> /// <param name="asyncStatus"></param> private void GetCurrentPosition(IAsyncOperation<Geoposition> asyncInfo, AsyncStatus asyncStatus) { Debug.WriteLine("获取到位置信息"); Geoposition currentGeoposition =asyncInfo.GetResults(); Geocoordinate coordinate= currentGeoposition.Coordinate; //获取的数据有偏差 LatLng currentLatLng = new LatLng(coordinate.Latitude + 0.000423, coordinate.Longitude + 0.006090); _daBeiJing = currentLatLng; Debug.WriteLine(currentLatLng); if(_amap!=null) { _amap.Dispatcher.BeginInvoke(() => { _amap.AnimateCamera(CameraUpdateFactory.NewCameraPosition(currentLatLng, 17, _bearing, _tile), 2);//移动视角(动画效果) _cameraIsNew = false; if (_locationMarker == null) { //添加圆 _circle = _amap.AddCircle(new AMapCircleOptions { Center = currentLatLng, //圆点位置 Radius = (float)20, //半径 FillColor = Color.FromArgb(80, 100, 150, 255),//圆的填充颜色 StrokeWidth = 1, //边框粗细 StrokeColor = Color.FromArgb(80, 100, 150, 255) //圆的边框颜色 }); //添加点标注,用于标注地图上的点 _locationMarker = _amap.AddMarker(new AMapMarkerOptions { Position = currentLatLng, //图标的位置 //待修改,更换IconUri的图标// IconUri = new Uri("Images/myLocationIcon.png", UriKind.RelativeOrAbsolute), //图标的URL Anchor = new Point(0.5, 0.5) //图标中心点 }); } else { //点标注和圆的位置在当前经纬度 _locationMarker.Position = currentLatLng; _circle.Center = currentLatLng; _circle.Radius = (float)20; //圆半径 } }); } }