Reputation:
I'm trying to build an application in JavaScript and I need to determine the country and the language of the user's location based on latitude/longitude.
It's easy if I use a remote API as the Google Maps API, but how can I do it without it? Just with the latitude and longitude?
var lat = 48.8534100;
var lng = 2.3488000;
// Get the country from lat, lng
// Then, get the language of the country
This application will be used in travel. That's why. Then, get the visited country and its language.
Upvotes: 0
Views: 411
Reputation: 79461
Use the OpenStreetMap API to get a set of country polygons. Store those in a database or file for offline local access. Query them offline.
After appropriate polygon resolution reduction on the country polygons — some of them may have borders much more detailed than you'll need — a simple linear run through all of the countries' polygons, doing a polygon-contains-point test for each one, should be plenty fast enough.
I've worked with OpenStreetMap before — it's really easy to extract the data you want.
Upvotes: 5