简体   繁体   English

javascript地理位置应该提示用户打开位置服务吗?

[英]Should javascript geolocation prompt user to turn on location services?

I am using the geolocation functionality to track user's locations with javascript. 我正在使用地理位置功能来通过javascript跟踪用户的位置。 More specifically, I am using navigator.geolocation.watchPosition. 更具体地说,我正在使用navigator.geolocation.watchPosition。 My site works fine. 我的网站工作正常。 When I visit my site on my Android device it prompts if I would like to allow the site to track my location. 当我在Android设备上访问网站时,它会提示我是否允许该网站跟踪我的位置。 I tap allow (as well as remember my preference). 我点击允许(以及记住我的偏好)。

After success with that I turned off location services on my phone and went back to the site. 成功之后,我关闭了手机上的定位服务,然后返回该站点。 It didn't prompt me for permission again (since I told it to remember my preference last time but it didn't prompt me to turn on my location services either. Needless to say at that point my site never got any geolocation data from the browser. 它没有再提示我一次许可(因为我上次告诉我要记住自己的偏好,但是它也没有提示我打开我的位置服务。不用说,那时我的网站从该网站上从未获得任何地理位置数据浏览器。

My question: Is there some way to prompt the user to turn on their location services programatically? 我的问题:是否可以通过某种方式提示用户以编程方式打开其位置服务? If I had not saved my security preference and it prompted me to allow again would it have turned on or asked me to turn on location services? 如果我没有保存我的安全首选项,它提示我再次允许它打开还是要求我打开定位服务? I would hate to have to tell the user they need to go into their cell phone's preferences to enable it. 我讨厌不得不告诉用户他们需要进入手机的偏好设置才能启用它。

It's browser specific or to be more exact - application specific. 它是特定于浏览器的,或更确切地说是特定于应用程序的。 What you could do is wait eg half a minute or a minute for the location and if it is not available show a warning to the user. 您可以做的是等待例如半分钟或一分钟的位置,如果该位置不可用,则向用户显示警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM