Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting CivicAddress on Windows Phone 8.1

I'm trying to get the CivicAddress from a Geoposition in Windows Phone 8.1

I've tried using the following code:

// Get Current Location
var geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 100;
var position = await geolocator.GetGeopositionAsync();

// Get Country
var country = position.CivicAddress.Country;

which throws NullReferenceException as the CivicAddress field is null. I understand that a CivicAddress provider is not provided for Windows 8. I would like to check whether this is the case for Windows Phone 8.1 If so, how can I obtain / write a CivicAddress provider?

like image 821
Kiang Teng Avatar asked May 16 '14 03:05

Kiang Teng


2 Answers

You will need to use ReverseGeocoding for this - some more information at MSDN.

As for windows runtime you can for example use MapLocationFinder.FindLocationsAtAsync for this purpose:

 var geolocator = new Geolocator();
 geolocator.DesiredAccuracyInMeters = 100;
 Geoposition position = await geolocator.GetGeopositionAsync();

 // reverse geocoding
 BasicGeoposition myLocation = new BasicGeoposition
     {
         Longitude = position.Coordinate.Longitude,
         Latitude = position.Coordinate.Latitude
     };
 Geopoint pointToReverseGeocode = new Geopoint(myLocation);

 MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

 // here also it should be checked if there result isn't null and what to do in such a case
 string country = result.Locations[0].Address.Country;
like image 96
Romasz Avatar answered Oct 01 '22 17:10

Romasz


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 here https://github.com/nokia-developer/maps-samples/tree/master/RevGeoCoding

else you could also try this to get civic address from GeoCoordinates http://msdn.microsoft.com/en-us/library/system.device.location.civicaddress(v=vs.110).aspx

like image 39
Gaurav Deochakke Avatar answered Oct 01 '22 16:10

Gaurav Deochakke