How to get the name of a country from latitude and longitude

How can I get a country name from latitude and longitude using C #? Im using the Bing.Map API

Location location12 = new Location(location.Latitude, location.Longitude); MapLayer.SetPosition(pin, location12); Map.Children.Add(pin); string placeName = GetPlaceNameForCoordinates(location.Latitude, location.Longitude); 
+3
source share
2 answers

You want to use the reverse geocoding API. For instance:

If you are already using the Bing.Maps SDK, you must use the Map.SearchManager property to get the SearchManager and then use the ReverseGeocodeAsync method. In particular, as noted in the comments, mixing and matching the API that you use to display data through other SDKs may violate the conditions of both: be careful what technologies you use within the same application. (Although this question provides sample code using the Bing Maps SDK, I have kept the list above to help others, which may have a slightly different context.)

For instance:

 var manager = map.SearchManager; var request = new ReverseGeocodeRequestOptions(location) { IncludeEntityTypeFlags = ReverseGeocodeEntityType.CountryRegion }; var response = await manager.ReverseGeocodeAsync( new ReverseGeocodeRequestOptions(location) { ); // Use the response 

If you decide to use the Geonames API, the data can also be downloaded for offline use.

+2
source

I created a github project with sample code that does this without api calls

see here

Very simple country name and id returned

0
source

Source: https://habr.com/ru/post/1241002/


All Articles