如何快速获取客户的地理位置(纬度和经度)?
我正在使用 Google 地图的 ClientLocation
来检索用户的地理位置(通过他们的 IP 地址)。这非常慢,因为您首先必须下载并加载 Google 地图,然后它才能开始对用户的 IP 地址进行地理定位。
然后我遇到了http://fwix.com/。他们正在做我想要的事情,而且速度超快,无需使用 Google 地图 ClientLocation
。
看来他们正在动态生成 HTML 页面,并将纬度和经度注入 HTML 的 META
区域。
只需查看 fwix.com 的源代码,您就会看到类似以下内容:
<meta name="geo_lat" content="12.34567" />
<meta name="geo_lng" content="-98.76543" />
问题:
- fwix 是如何做到这一点的?
- 无需加载整个 Google 地图 API 即可检索用户地理位置(纬度/经度)的最快方法是什么?意思是,如果有一个我可以通过编程调用的网络服务,它会简单地返回用户的地理位置(纬度/经度)?
I am using Google Map's ClientLocation
to retrieve the users geolocation (via their IP address). This is very slow because you first have to download and then load Google Maps, before it can even begin to geolocate the users IP address.
Then I came across http://fwix.com/. They are doing exactly what I want, but super fast without having to use Google Maps ClientLocation
.
It appears they are generating the HTML page on the fly and injecting the latitude and longitude into the META
area of the HTML.
Just view the source for fwix.com and you'll see something like:
<meta name="geo_lat" content="12.34567" />
<meta name="geo_lng" content="-98.76543" />
Questions:
- How does fwix doing this?
- What is the quickest way for me to retrieve a users geolocation (lat/lng) without having to load the entire Google Maps API? Meaning, if there a web service I can call programically that will simply return the users geolocation (lat/lng)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要客户端进行任何交互(除了初始请求(向服务器显示其 IP 地址))即可通过 IP 地址找到它们。
通过 IP 进行的地理定位全部在服务器端完成,并且可以快速转发到客户端。如果您遇到加载缓慢的情况,那是因为您的浏览器正在加载其他内容。
You don't need any interaction from the client (besides their initial request, which reveals their IP address to the server) to locate them by their IP address.
Geolocation via IP is all done on the server side, and this can be quickly relayed to the client. If you experience slow loading, that's because your browser is loading something else.