从网络浏览器获取 GPS 位置
我正在开发一个基于移动设备的网站,在那里我集成了谷歌地图,我需要动态填写谷歌地图的“发件人”字段。
是否可以从网络浏览器获取 GPS 位置并将其动态填充到 Google 地图的“发件人”字段中?
I am developing a mobile based web-site, there I have integrated Google Maps, I need to fill the 'From' field of Google Maps dynamically.
Is it possible to get the GPS location from web browser and fill it up in the 'From' field of a Google Map dynamically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您使用 Geolocation API,则如下简单如使用以下代码。
您还可以使用Google 的客户端位置 API。
此问题已在是否可以检测到移动浏览器的 GPS 位置? 和从移动浏览器获取位置数据 。您可以在那里找到更多信息。
If you use the Geolocation API, it would be as simple as using the following code.
You may also be able to use Google's Client Location API.
This issue has been discussed in Is it possible to detect a mobile browser's GPS location? and Get position data from mobile browser. You can find more information there.
请参阅讨论如何在浏览器中获取 GPS 坐标
这里有示例应用程序的链接我在哪里?< /a> 适用于移动设备。我在我的 Android 上测试了它,它启动了 GPS 模块来获取当前坐标。您可以在活生生的例子上分析来源。
我制作了 QR 码以便从移动设备快速访问:
See the discussion How to get GPS coordinates in the browser
There you have the link to example application Where Am I? that works on mobile devices. I've tested it on my Android and it started GPS module to get current coordinates. You can analyze the source on the living example.
I've made QR code for quick access from mobile:
给出更具体的答案。 HTML5 允许您获取地理坐标,而且它做得相当不错。总体而言,浏览器对地理定位的支持非常好,除了 ie7 和 ie8(以及 Opera mini)之外的所有主流浏览器。 IE9 可以完成这项工作,但性能最差。查看 caniuse.com:
http://caniuse.com/#search=geol
此外,您还需要获得批准您的用户访问其位置的权限,因此请务必检查这一点,并提供一些适当的说明,以防其关闭。特别是对于Iphone来说,打开Safari的权限有点麻烦。
To give a bit more specific answer. HTML5 allows you to get the geo coordinates, and it does a pretty decent job. Overall the browser support for geolocation is pretty good, all major browsers except ie7 and ie8 (and opera mini). IE9 does the job but is the worst performer. Checkout caniuse.com:
http://caniuse.com/#search=geol
Also you need the approval of your user to access their location, so make sure you check for this and give some decent instructions in case it's turned off. Especially for Iphone turning permissions on for Safari is a bit cumbersome.
使用它,您将在 http://www.w3schools.com/html/html5_geolocation 找到所有信息.asp
Use this, and you will find all informations at http://www.w3schools.com/html/html5_geolocation.asp
有 GeoLocation API,但浏览器支持相当薄弱目前接地。大多数关心此类事情的网站都使用 GeoIP 数据库(通常会附带有关此类系统不准确的条件)。您还可以查看需要用户合作的第三方服务,例如 FireEagle。
There is the GeoLocation API, but browser support is rather thin on the ground at present. Most sites that care about such things use a GeoIP database (with the usual provisos about the inaccuracy of such a system). You could also look at third party services requiring user cooperation such as FireEagle.
可观察的
Observable
让我们使用最新的粗箭头函数:
Let's use the latest fat arrow functions: