【发布时间】:2014-05-04 12:58:06
【问题描述】:
我正在尝试通过 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;
});
}
也已尝试使用 地理位置。仍然抛出异常。试过条件检查,没用。请帮忙
[更新]
按钮点击:
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";
}
【问题讨论】:
-
您在哪一行得到异常?
-
Tblock.Text = args.Position.CivicAddress.Country;
-
你能提供更多代码吗?
-
完成。 geolocator_PositionChanged 仅包含一个用于检查定位器状态的开关盒。它很长,这就是我没有添加它的原因。
标签: windows-phone-8 geolocation