문제

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

다른 팁

        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.");
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top