To co zrobiłem pod koniec dnia. Pierwszy użyłem biblioteki Lokalizacja API, aby uzyskać współrzędne (długość i szerokość geograficzna) położenia
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
// Request the current position
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
string latitude = geoposition.Coordinate.Latitude.ToString("0.00");
string longitude = geoposition.Coordinate.Longitude.ToString("0.00");
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x80004004)
{
// the application does not have the right capability or the location master switch is off
MessageBox.Show("Location is disabled in phone settings.", "Can't Detect Location", MessageBoxButton.OK);
}
//else
{
// something else happened acquring the location
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
następnie stosując odwrotną geolokalizacji Google, aby uzyskać informacje lub dane o lokalizacji na podstawie długości i szerokości geograficznej
http://maps.googleapis.com/maps/api/geocode/json?latlng=latitiude,longitude&sensor=true
czyli jeżeli szerokość wynosi 60, a długość geograficzna to 60
http://maps.googleapis.com/maps/api/geocode/json?latlng=60,60&sensor=true
Od wyniku json, będzie można odzyskać w kraju długie i krótkie Nazwa.
Co otrzymujesz z RegionInfo.CurrentRegion.DisplayName? –
Otrzymuję ten sam wynik "Stany Zjednoczone" przy użyciu parametru RegionInfo.CurrentRegion.DisplayName – jade
Czy próbowałeś testować na rzeczywistym urządzeniu? –