Get Civic Address in Windows Phone 8

℡╲_俬逩灬. 提交于 2019-12-10 11:43:58

问题


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";
}

回答1:


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




回答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.");
        }


来源:https://stackoverflow.com/questions/23447215/get-civic-address-in-windows-phone-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!