Search code examples
c#geolocationgeonames

C# - Get Country from latitude/longitude without API


Is it possible with a C# library or an update database about geographical coordinates coutries to get the country name from latitude and longitude Without an API like the Google Maps’ JavaScript API ?


Solution

  • You can do it. If you don't need a lot of accuracy, you can use a table with coordinates of countries. And determine nearest country coordinate. But it is bad way.

    Good solution is you get a KML file of country borders. But you will need good algorithm to detemine in border of which country your point is. The algorithm for finding posiiton of point and polygon is described here. Also there are some answers on stackoverflow 1, 2, but it's for plane.

    Also possible way is to precalculate countries for coordinates with some small step(e.g. 30'') and determine coutry by finding nearest precalculated point to your point. You can precalculate country with a lot of online services.