【问题标题】:Get Civic Address in Windows Phone 8在 Windows Phone 8 中获取公民地址
【发布时间】: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


【解决方案1】:

如果您想获取某个职位的地址,那么我建议您将 ReverseGeocodeQuery API 与您通过 Geolocator API 获得的职位一起使用,作为参考实现,我在 github 上提供了一个示例

【讨论】:

    【解决方案2】:
            var reportstatus = CivicFactory.Status;
    
            if (reportstatus == 4)
            {     
                var report = CivicFactory.CivicAddressReport;
    
                // Display the properties.
                tx1.value = report.AddressLine1;
                tx2.value = report.AddressLine2;
                tx3.value = report.City;
                tx4.value = report.StateProvince;
                tx5.value = report.CountryRegion;
                tx6.value = report.PostalCode;
                tx7.value = GetTimeString(report.Timestamp); 
            }
            else
            {
                alert("No location data provider available.");
            }
    

    【讨论】:

    • 思域工厂?这是哪里来的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多