void ageol_PositionChanged(AGeolocator sender, APositionChangedEventArgs args) { this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { if (!map.Children.Contains(marker)) { marker.LngLat = new ALngLat(113.38563, 23.05810); map.Children.Add(marker); } else { marker.LngLat = new ALngLat(113.38563, 23.05810); } map.SetZoomAndCenter(20, marker.LngLat); Debug.WriteLine("定位精度:" + args.Accuracy);//单位米 }); }
void ageol_PositionChanged(AGeolocator sender, APositionChangedEventArgs args) { this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { if (!map.Children.Contains(marker)) { marker.LngLat = args.LngLat; map.Children.Add(marker); } else { marker.LngLat = args.LngLat; } map.SetZoomAndCenter(15, args.LngLat); Debug.WriteLine("定位精度:" + args.Accuracy);//单位米 }); }
void ageol_PositionChanged(AGeolocator sender, APositionChangedEventArgs args) { pick = true;//确定marker已选 //map.Children.Add(marker); this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { //第一次定位 if (!map.Children.Contains(marker)) { marker.LngLat = args.LngLat; //点标注的经纬度为当前定位获取的经纬度 map.Children.Add(marker); //将点标注添加到地图上 } //位置改变时的定位 else { marker.LngLat = args.LngLat; } map.SetZoomAndCenter(15, args.LngLat); Debug.WriteLine("定位精度:" + args.Accuracy);//单位米 }); }
void ageol_PositionChanged(AGeolocator sender, APositionChangedEventArgs args) { this.Dispatcher.RunAsync(CoreDispatcherPriority.High, async() => { CurrentLocation = args.LngLat; try { //update current location if (this.currentViewType != null && this.currentViewType == typeof(MapView)) { AMarker marker = new AMarker(); marker.LngLat = this.CurrentLocation; marker.IconURI = new Uri("http://api.amap.com/webapi/static/Images/marker_sprite.png "); ATip tip = new ATip(); tip.Title = "当前位置"; tip.ContentText = "Current Position"; marker.TipFrameworkElement = tip; this.map.Children.Clear(); this.map.Children.Add(marker); marker.OpenTip(); } if (DateTime.Now.ToFileTime() - lastUpdate.ToFileTime() < 30000000) { return; } //convert location to sogo location string points = string.Format("{0},{1}", CurrentLocation.LngX, CurrentLocation.LatY); string url = SogoMapService.GetTranslationInfoURL(points); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url); HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); string result = ""; using (Stream responseStream = await response.Content.ReadAsStreamAsync()) { int read = 0; byte[] responseBytes = new byte[1000]; do { read = await responseStream.ReadAsync(responseBytes, 0, responseBytes.Length); string tmp = System.Text.Encoding.GetEncoding("GBK").GetString(responseBytes, 0, read); result += tmp; }while (read != 0); } TranslationLocation translation = SogoMapService.GetTranslationInfo(result); if (translation != null && translation.response.points.Length == 1) { this.CurrentSogoLongitude = translation.response.points[0].longitude; this.CurrentSogoLatitude = translation.response.points[0].latitude; } } catch { } //check whether need alert this.CheckReminder(); this.lastUpdate = DateTime.Now; }); }