Web应用程序如何询问移动设备的位置? [英] How web apps ask location of mobile device?

查看:118
本文介绍了Web应用程序如何询问移动设备的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多现代手机(谷歌Nexus One等)都有一些内置的位置服务。
当我去某个网站(例如。google.com)时,网站会询问我是否愿意与该网站分享我的位置。



你是否真的要求移动设备发布它的位置?该地点的格式是什么?

解决方案

iPhone,Android或者其他应用程序上的Web应用程序即使某些桌面浏览器(Firefox,Chrome和Opera的某些最新版本)也使用 W3C地理定位API 来请求您的位置。 Google Gears还支持类似的地理位置API,作为许多浏览器的插件,但W3C API正在成为标准。



检查API支持的代码,然后请求位置很简单( if(navigator.geolocation)... )。一些示例代码此处


Many modern mobile phones (google nexus one etc.) have some kind of built in location service. when i go to a some website (eg. google.com) that website asks if I'm willing to share my location with that site.

How do you actually ask for mobile device to give out it's location to the site? And in what format is that location given? I've got no clue and didn't find any answers from google, neither.

解决方案

Web applications on iPhone, Android or even certain desktop browsers (some recent versions of Firefox, Chrome and Opera) use the W3C Geolocation API to request your location. Google Gears also supports a similar geolocation API as a plugin for many browsers, but the W3C API is becoming the standard.

The code to check for support of the API and then request a location is straightforward (if (navigator.geolocation) ...). Some sample code here.

这篇关于Web应用程序如何询问移动设备的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆