Reputation: 487
I was just wandering how I can get the current location of the device. Now, when I tried to do this using Geolocator it didn't work. It just gave me the Longitude and Latitude. I don't want this I want the names of the street or city or suburb etc... an example would be the HERE Transit
app by Nokia. When you go to the 'Nearby' tab, you get a map and beneath that is the street name, suburb and then city and postcode.
How can I do this? what I have right now is:
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
Geoposition geoposition = await geolocator.GetGeopositionAsync();
test.Text = geoposition.Coordinate.Latitude.ToString("0.00");
testt.Text = geoposition.Coordinate.Longitude.ToString("0.00");
}
catch (UnauthorizedAccessException)
{
}
Basically this gives me the Longitude and Latitude. Maybe I can use these to get the names of the street or city etc but HOW?
I've never really used the MAPS or anything to do with Location when programming. So how can I achieve this?
Thanks
Upvotes: 0
Views: 725
Reputation: 15268
This is called reverse geocoding. Here is a sample code that does that:
MapAddress address;
ReverseGeocodeQuery query = new ReverseGeocodeQuery();
query.GeoCoordinate = myGeoCoordinate;
query.QueryCompleted += (s, e) =>
{
if (e.Error != null)
return;
address = e.Result[0].Information.Address;
};
query.QueryAsync();
That API is available on Windows Phone 8 and I see the question is tagged WP7 but since you seem to use the Geolocator
API, I guess you are on WP8. Otherwise, you'd have to use this kind of service: Find a Location by Point
Upvotes: 1