简体   繁体   中英

Detect country and language of the user's location offline

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM