简体   繁体   English

离线检测用户所在位置的国家和语言

[英]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. 我正在尝试使用JavaScript构建应用程序,并且需要根据纬度/经度确定用户所在国家/地区和语言。

It's easy if I use a remote API as the Google Maps API, but how can I do it without it? 如果我将远程API用作Google Maps API很容易,但是如果没有远程API,我该怎么办呢? 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. 使用OpenStreetMap API可以获取一组国家/地区多边形。 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. 我之前使用过OpenStreetMap-提取所需的数据确实很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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