谷歌地图和 HTML5 中的地理位置
我正在研究基于位置的服务。我找不到与以下查询相关的任何明确答案,因此我询问 -
如何在我们自己的服务器中启用 HTML5 地理定位?或者是否有任何中央地理定位数据库默认提供位置服务(如 DNS)?
我很惊讶地看到我的笔记本电脑(显然没有 GPS)中的谷歌地图(http://html5demos.com/geo)中的地理定位精度在约 20M 范围内。技术是什么?如何在我们自己的系统中实现呢?
当我过去搜索我的 IP 位置时,它通常会在地图上显示 ISP 办公室,距离大约 15 公里远,而最近的情况则显示几乎准确的位置。可能是什么原因?难道是因为我使用 Android 手机使用相同的无线路由器,并且它从那里获取位置?或者在 HTML5 中,他们开始定位特定的 IP 地址(这似乎不太可能)。
I am working on location based service. I couldn't find any clear answer related to my following queries and so am asking-
How to enable HTML5 geolocation in our own server? Or is there any central geolocation DB there which will provide location service by default (like DNS)?
I was stunned seeing the accuracy of geolocation in google map (http://html5demos.com/geo) in my laptop (obviously GPS free) which is within ~20M range. What is the technology? How to implement that in our own system?
When I used to search my IP location, it used to show the ISP office in the map which is ~15 KM further as opposed to recent situation where it is showing almost exact location. What might be the reason? could it be because I use my android phone using the same Wireles router and it takes the location from there? Or in HTML5 they started locating specific IP addresses (which seems somewhat unlikely).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以在优秀的 Dive Into 中找到有关其工作原理以及如何在您自己的网站中使用它的大量信息HTML 5。本书推荐使用 Modernizr,提供了一个简单的示例:
它在笔记本电脑上工作的主要方式是通过使用本地无线的已知位置
接入点。不同浏览器的情况略有不同 - firefox 这里有一个很好的解释。他们使用Google 的定位服务,它们是通过谷歌街景汽车绘制的地图创建的。
You can find a lot of information on how this works and how to use it in your own websites in the excellent Dive Into HTML 5. This book recommends using Modernizr, a simple example of which is provided:
The primary way it is working on your laptop is by using the known positions of local wireless
access points. This varies a little from browser to browser - firefox has a good explanation here. They use positioning services from Google, which were created by mapping done by Google's Street View cars.
现在检查 GetCords 函数
now check the GetCords function
来自
http:// /robertnyman.com/2010/03/15/geolocation-in-web-browsers-to-find-location-google-maps-examples/
From
http://robertnyman.com/2010/03/15/geolocation-in-web-browsers-to-find-location-google-maps-examples/
其实很简单。上面来自 Dive into HTML 的示例并不完整,因为它没有显示 show_map 函数,该函数是用户创建的函数,实际上读取传入数据并对其执行某些操作。下面是一个更完整的示例:
这个示例(来自我即将出版的 HTML5 书籍)有一个由 body onload 机制调用的 getLoc() 函数。这使用 navigator.geolocation.getCurrentPosition() 函数来请求权限向量。它将弹出一个权限对话框,如果用户选择不共享当前位置,该对话框将被拒绝。如果用户确实一起玩,将显示指定的回调函数(在我的例子中为 showMap)。
回调函数自动接受特殊位置对象作为其唯一参数。该对象具有许多潜在有用的属性,但纬度和经度是最有帮助的。您可以使用这些值来简单地打印出当前位置。您还可以将这些值连接到 Google 地图 URL 中,以获取当前位置的快速 Google 地图。我还在当前页面中嵌入了 Google 地图,并更改了嵌入 (iframe) 地图的 URL 以获取即时反馈。
希望这有帮助!
It's actually pretty simple. The above example from Dive into HTML is incomplete, as it doesn't show the show_map function, which is a user-created function that actually reads the incoming data and does something with it. Here's a more complete example:
This example (from my upcoming HTML5 book) has a getLoc() function called by the body onload mechanism. This uses the navigator.geolocation.getCurrentPosition() function to request a permission vector. It will pop up a permission dialog, which will be rejected if the user chooses not to share her current position. If the user does play along, the indicated callback function (in my case showMap) will be displayed.
The callback function automatically accepts a special position object as its only parameter. This object has a number of potentially useful attributes, but latitude and longitude are the most helpful. You can use these values to simply print out the current position. You can also concatenate these values into a Google maps URL to get a quick Google map of the current location. I also embedded a Google map into my current page, and changed the URL of the embedded (iframe) map to get immediate feedback.
Hope this helps!
试试这个代码
Try This Code