navigator.geolocation.getCurrentPosition no longer working in Safari mobile after iOS9 update

只愿长相守 提交于 2019-12-07 23:14:45

问题


I have a web app that has this code for getting the user's coordinates:

if (navigator.geolocation) {
   navigator.geolocation.getCurrentPosition(function(position) {  

But the moment I updated to iOS9 it ceased to work. I'm not even getting the Safari prompt anymore asking permission to get my location. Anyone else having this issue after updating to iOS9 and was able to resolve it?


回答1:


I've noticed this myself and i'm wondering if iOS 9 Webkit has started to prevent this working via HTTP as I know Chrome will be preventing this shortly as it currently throws the following alert in the web console.

getCurrentPosition() and watchPosition() are deprecated on insecure origins, and support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.




回答2:


Try enabling localization in the general settings of iOS. Settings > Localization > Press localization to enable it. And now it works.

It seems that iOS 9 has disabled localization in the settings, after installing.




回答3:


If you are running on a mac, you'll need to enable location services for safari: enable location on OSX



来源:https://stackoverflow.com/questions/32720308/navigator-geolocation-getcurrentposition-no-longer-working-in-safari-mobile-afte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!