5

Próbuję uzyskać CivicAddress od A Geoposition w Windows Phone 8.1Pierwsze CivicAddress na Windows Phone 8.1

Próbowałem za pomocą następującego kodu:

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

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

który rzuca NullReferenceException jako CivicAddress pole ma wartość NULL. Rozumiem, że dostawca usługi CivicAddress nie jest dostępny dla systemu Windows 8. Chciałbym sprawdzić, czy tak jest w przypadku systemu Windows Phone 8.1. Jeśli tak, jak mogę uzyskać/napisać dostawcę CivicAddress?

Odpowiedz

14

trzeba będzie użyć ReverseGeocoding tego - trochę więcej informacji at MSDN.

chodzi o Windows Runtime można na przykład używać MapLocationFinder.FindLocationsAtAsync do tego celu:

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; 
+0

DZIĘKUJEMY! Długo szukałem rozwiązania WinRT. To po prostu działa. –

+0

@ScottNimrod Nie ma za co. Cieszę się, że pomogło. – Romasz

+1

Tutaj nie ma potrzeby tworzenia nowej lokacji BasicGeoposition myLocation, można użyć bezpośrednio position.Coordinate.Point jako parametru do obiektu MapLocationFinder.FindLocationsAtAsync(); – vITs