关于ios11和Chrome浏览器非HTTPS 对高德定位不支持问题

   最近,在开发二维码签到系统时,需要对用户的签到的经纬度进行获取,并且判断签到距离是否在可支持范围内。

   使用了高德地图。因为本人最近刚刚入手了一款新的Iphone7里面是最新的ios11系统。发现我的手机总是定位失败。后来查阅知,现在Chrome浏览器和ios等系统需要HTTPS才可以获得定位。其他安卓手机都正常。最后在高德地图的问题中心找到了解决办法。

  

苹果新发的 iOS 11 操作系统的一大特性是对 http 形式访问页面的限制变得非常严格(相比iOS 10 和 iOS 9)。

高德提供的JS API功能均支持http和https两种协议访问,在iOS 11操作系统上推荐使用https形式访问功能页面和接口。

 

  • 请先将JS API的版本升级到1.4.1版本:
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.0&key=您申请的key值"></script> 

 

  • 然后需要满足以下两点:

1、需要使用JS API的高精度定位功能,在iOS 11上,请通过https访问定位。

2、您的个人(或企业)网站在iOS 11系统下也请您调整成https形式对终端用户提供。

如果修改之后依旧发生定位失败的情况,请参考如下:

 

  • 类似 Chrome 等浏览器框架目前禁止非 https 环境进行定位,请在iOS11下尝试访问如下页面:

1、可以成功定位的页面地址:http://a.amap.com/jsapi_demos/static/remogeo/remo.html

2、需要引入的remogeo.js ,建议放置在本地:http://a.amap.com/jsapi_demos/static/remogeo/remogeo.js

3、重点需要关注的代码:

<!-- 加载远程定位脚本 -->
        <script type="text/javascript" src="./remogeo.js"></script>
// ios环境切换到使用远程https定位
                    if (AMap.UA.ios && document.location.protocol !== 'https:') {
                        //使用远程定位,见 remogeo.js
                        var remoGeo = new RemoGeoLocation();
                        //替换方法
                        navigator.geolocation.getCurrentPosition = function() {
                            return remoGeo.getCurrentPosition.apply(remoGeo, arguments);
                        };
                        //替换方法
                        navigator.geolocation.watchPosition = function() {
                            return remoGeo.watchPosition.apply(remoGeo, arguments);
                        };
                    }

 

  • iOS 11下WebView定位超时可做如下调整:
//在info.plist添加
Privacy - Location When In Use Usage Description

日志现象:

webview[6877:601452] This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSLocationWhenInUseUsageDescription key with a string value explaining to the user how the app uses this data
posted @ 2018-04-01 09:03  ZzUuOo666  阅读(3062)  评论(5编辑  收藏  举报