Reputation: 275
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";
}
Upvotes: 1
Views: 495
Reputation: 452
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.");
}
Upvotes: 0