Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 745
k4st0r42 Avatar asked Jan 20 '16 09:01

k4st0r42


2 Answers

I've created a github project that will get country or american state based on gps point (lat ; lon) see here

if found, will return a locationInfo class with Id and Name

also available as a nuget package

like image 69
InquisitorJax Avatar answered Oct 16 '22 13:10

InquisitorJax


You can use GeoNames and download a local database here.

And so, this is a sample query that you can use to obtain the nearest entry from a lat/long coordinate.

var query = new SQLiteCommand("select name,latitude,longitude,country_code,feature_code from geoloc order by ((latitude - @lat) * (latitude - @lat) + (longitude - @lng) * (longitude - @lng)) LIMIT 1, cn);
like image 3
sborfedor Avatar answered Oct 16 '22 13:10

sborfedor