public ContentResult GetMap1() { List <AMapMarker> list = new List <AMapMarker>(); //ViewBag.MapCoordinate = new List<AMapMarker>() //{ // new AMapMarker // { // Id = "4", // Latitude = 116.664, // Longitude = 39.915, // ImageName = "/Content/images/t06.png", // Contents = "节点编号0000</br>状态:456", // } //}; Random r = new Random(); for (int i = 0; i < 50; i++) { AMapMarker marker = new AMapMarker(); marker.Id = i.ToString(); marker.Latitude = r.Next(30, 120) + r.NextDouble(); marker.Longitude = r.Next(30, 120) + r.NextDouble(); marker.ImageName = "/Content/images/t06.png"; marker.Contents = "节点编号" + i + "</br>状态:456"; list.Add(marker); } ViewBag.MapCoordinate = list; return(Content("success")); }
private void amap_MarkerClickListener(AMapMarker sender, AMapEventArgs args) { sender.ShowInfoWindow(new AInfoWindow() { Title = sender.Title, //ContentText = sender.Snippet, }); }
private void Button_DrawCircle_Click(object sender, RoutedEventArgs e) { marker = amap.AddMarker(new AMapMarkerOptions() { Position = amap.Center, Title = "Title", Snippet = "Snippet", IconUri = new Uri("Images/AZURE.png", UriKind.Relative), }); this.btnVisible.IsEnabled = true; }
/// <summary> /// 显示/隐藏弹出信息 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void ShowMarkerInfo(AMapMarker sender, AMapEventArgs args) { if (sender.IsInfoWindowShown()) { //隐藏弹出信息 sender.HideInfoWindow(); } else { //显示弹出信息 MarkerInfo info = new MarkerInfo(); sender.ShowInfoWindow(info, new Point(0, 0)); } }
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), }); }); }
private void amap_Loaded(object sender, RoutedEventArgs e) { this.Dispatcher.BeginInvoke(() => { //设置默认的地图经纬度和缩放级别 amap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(39.987326, 116.48236), 13)); ////实例化标注点 AMapMarkerOptions opt = new AMapMarkerOptions() { Position = new LatLng(39.987326, 116.48236), Title = "这是一个marker", IconUri = new Uri("Images/AZURE.png", UriKind.Relative), Anchor = new Point(0.5, 0.5),//图标中心点 }; //添加点 marker = amap.AddMarker(opt); amap.MarkerClickListener += amap_MarkerClickListener; }); }
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); }); }
/// <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); }); }
/// <summary> /// 供SearchPage返回时调用 /// </summary> /// <param name="e"></param> protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); var app = Application.Current as App; if (app != null && app.IsFromSearchPage) { double lat = double.Parse(NavigationContext.QueryString["lat"]); double lon = double.Parse(NavigationContext.QueryString["lon"]); _address = NavigationContext.QueryString["address"]; _researchLatLng = new LatLng(lat, lon);//新建经纬度,供标记搜索maker使用 _cameraIsNew = false;//防止实时定位视角拉动 //绘制搜索结果maker _researchMarker = _amap.AddMarker(new AMapMarkerOptions() { Position = _researchLatLng,//maker添加位置 IconUri = new Uri("Images/RED.png", UriKind.RelativeOrAbsolute)//maker图标 }); (Application.Current as App).IsFromSearchPage = false; _amap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(_researchLatLng, 16));//移动视角 ShowDownStateSettings(); MakerTextBlock.Text = _address; //GetNavigationDriving(Location, _researchLatLng); } }
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> /// 标记后显示该位置的相关信息(地理位置名称等信息) ///地图maker标记函数(长按) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void amap_hold(object sender, GestureEventArgs e) { //获取用户标识点所在位置经纬度 TabLatLng = _amap.GetProjection().FromScreenLocation((e.GetPosition(_amap))); //删除用户先前标识的_tabMaker if (_tabMarker != null) _tabMarker.Destroy(); //创建新的_tabMaker _tabMarker = _amap.AddMarker(new AMapMarkerOptions() { Position = TabLatLng,//maker添加位置 IconUri = new Uri("Images/RED.png", UriKind.RelativeOrAbsolute)//maker图标 }); NavigateEndLngLng = TabLatLng; //纠正定位偏差,将搜索半径设置为50米 amapHoldResult = await AMapReGeoCodeSearch.GeoCodeToAddress(TabLatLng.longitude, TabLatLng.latitude,50, "", Extensions.All); //amapHoldResult = await AMapReGeoCodeSearch.GeoCodeToAddress(TabLatLng.longitude, TabLatLng.latitude); Dispatcher.BeginInvoke(() => { if (amapHoldResult.Erro == null && amapHoldResult.ReGeoCode != null) { AMapReGeoCode regeocode = amapHoldResult.ReGeoCode; ShowDownStateSettings(); MakerTextBlock.Text = regeocode.Formatted_address; } } ); }
/// <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; //圆半径 } }); } }
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)); }