ios11 系统 微信公众号 高德地图定位失败
类似 Chrome 等浏览器框架目前禁止非 https 环境进行定位,请在iOS11下尝试访问如下页面:
1、可以成功定位的页面地址:http://a.amap.com/jsapi_demos/static/remogeo/remo.html
2、需要引入的remogeo.js ,本地新建一个js文件,将以下网址内容添加进去,http://a.amap.com/jsapi_demos/static/remogeo/remogeo.js
3、重点需要关注的代码:
<!-- 加载远程定位脚本 -->
<script type="text/javascript" src="./remogeo.js"></script>
mapObj.plugin('AMap.Geolocation', function() {
geolocation = new AMap.Geolocation({
enableHighAccuracy: true,//是否使用高精度定位,默认:true
timeout: 10000, //超过10秒后停止定位,默认:无穷大
buttonOffset: new AMap.Pixel(10, 50),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
buttonPosition:'RT'
});
// ios环境切换到使用远程https定位 (放在初始化地图后面)
if (AMap.UA.ios) {
//使用远程定位,见 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);
};
}