网站:使用用户位置查找最近的办公室以更改网站上的信息

时间:2018-06-26 00:45:58

标签: html5 web mobile geolocation ip-geolocation

我正在尝试建立一个用于工作的“事件日历”网站。

我的作品在全国各地设有办事处,因此他们希望在用户访问其知道距最近办事处的位置(无论如何都会在办事处使用)的网站时实施该操作,从而更改网站。

该网站基本上是:

Welcome! Are you in <office location>?

(会有一个下拉菜单,用于手动选择站点)

根据位置,该办公室后面会出现一个事件日历。

我尝试研究各种答案,例如HTML和Google Maps的地理位置。但是他们只谈论在地图元素上显示位置。我只想找到它们的坐标并将其放到最近的办公室,以通过HTML元素显示为文本。

有什么帮助吗?

谢谢你

1 个答案:

答案 0 :(得分:0)

您是否尝试过任何IP地理位置API?尽管IP地理位置的准确性并不总是准确的,因为这些服务默认位于城市中心。您可以签出ipgeolocation.io,它提供了将以编程方式使用的地理坐标。这是在用户浏览器上调用时的示例响应。

curl 'https://api.ipgeolocation.io/ipgeo?apiKey=API_KEY'
{
"ip": "33.33.33.33",
"continent_code": "NA",
"continent_name": "North America",
"country_code2": "US",
"country_code3": "USA",
"country_name": "United States",
"country_capital": "Washington",
"state_prov": "Ohio",
"district": "Franklin County",
"city": "Columbus",
"zipcode": "43218",
"latitude": "39.9747",
"longitude": "-82.8948",
"is_eu": false,
"calling_code": "+1",
"country_tld": ".us",
"languages": "en-US,es-US,haw,fr",
"country_flag": "https://ipgeolocation.io/static/flags/us_64.png",
"isp": "DoD Network Information Center",
"connection_type": "wired",
"organization": "DoD Network Information Center",
"geoname_id": "4510575",
"currency": {
    "name": "Dollar",
    "code": "USD"
},
"time_zone": {
    "name": "America/New_York",
    "offset": "-4",
    "is_dst": true,
    "current_time": "2018-05-14 15:54:13.975-0400"
}
}