在Windows Phone 8中获取思域地址 [英] Get Civic Address in Windows Phone 8

查看:97
本文介绍了在Windows Phone 8中获取思域地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过WP8中的Geolocator获得公民地址。但它抛出一个 System.NullReferenceException

  private void geolocator_PositionChanged(Geolocator sender,PositionChangedEventArgs args)
{
Dispatcher.BeginInvoke(()=>
{
LatitudeTextBlock.Text = args.Position.Coordinate.Latitude.ToString();
LongitudeTextBlock.Text = args .Position.Coordinate.Longitude.ToString();
Tblock.Text = args.Position.CivicAddress.Country;
});
}

也已经尝试过 Geoposition 。仍然抛出异常。尝试了一个有条件的检查,没用。请帮助

[更新]

按钮点击:

  private void TrackLocation_Tap(object sender,System.Windows.Input.GestureEventArgs e)
{
Geolocator geolocator = new Geolocator ();
geolocator.DesiredAccuracy = PositionAccuracy.High;
geolocator.MovementThreshold = 1; //这个单位是Meters
geolocator.StatusChanged + = geolocator_StatusChanged;
geolocator.PositionChanged + = geolocator_PositionChanged;
TrackLocation.Content =停止追踪;


解决方案

如果您想获得地址对于一个职位,那么我会建议你使用Reverse GeocodeQuery API与你使用Geolocator API的位置,以供参考实现我有一个例子可在 github


I'm trying to get the civic address via Geolocator in WP8. But it throws a System.NullReferenceException

private  void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
     Dispatcher.BeginInvoke(() =>
      {
           LatitudeTextBlock.Text = args.Position.Coordinate.Latitude.ToString();
           LongitudeTextBlock.Text = args.Position.Coordinate.Longitude.ToString();
           Tblock.Text = args.Position.CivicAddress.Country;
      });
}

already tried with Geoposition also. Still throws exception. Tried a conditional check, no use. Please help

[UPDATE]

The button click:

private void TrackLocation_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
     Geolocator geolocator = new Geolocator();
     geolocator.DesiredAccuracy = PositionAccuracy.High;
     geolocator.MovementThreshold = 1; // This units are in Meters
     geolocator.StatusChanged += geolocator_StatusChanged;
     geolocator.PositionChanged += geolocator_PositionChanged;
     TrackLocation.Content = "Stop Tracking";
}

解决方案

If you want to get address for a position, then I would suggest you use ReverseGeocodeQuery API with the position you get with the Geolocator API, for reference implementation I do have an example available at github

这篇关于在Windows Phone 8中获取思域地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆