高德地图api 用web开发的。实现了定位功能与将经纬度转化为详细地址。然后将该功能嵌入到手机app中,结果ios11系统不能使用,有大神知道原因吗?
高德地图api 用web开发的。实现了定位功能与将经纬度转化为详细地址。然后将该功能嵌入到手机app中,结果ios11系统不能使用,有大神知道原因吗?
代码:<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="HandheldFriendly" content="true">
<title>按起终点名称规划路线</title>
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
<style>
#panel {
position: fixed;
background-color: white;
max-height: 50%;
overflow-y: auto;
top: 10px;
width: 30%;
}
</style>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.0&key=960a8815b9c37ca8268b2c7e6f041cf4&plugin=AMap.Driving"></script>
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
<script type="text/javascript" src="http://a.amap.com/jsapi_demos/static/remogeo/remogeo.js"></script>
</head>
<body>
<p id="container"></p>
<div id="mainMap"></div>
<div id="panel" style="width:100%; height:10%; overflow:hidden;" ></div>
<input type="text" value="成都市中和中学" id="df"/>
</body>
</html>
<script type="text/javascript">
var map, geolocation;
//加载地图,调用浏览器定位服务
map = new AMap.Map('container', {
resizeEnable: true
});
map.plugin('AMap.Geolocation', function() {
geolocation = new AMap.Geolocation({
enableHighAccuracy: true, //是否使用高精度定位,默认:true
timeout: 10000, //超过10秒后停止定位,默认:无穷大
maximumAge: 0, //定位结果缓存0毫秒,默认:0
convert: true, //自动偏移坐标,偏移后的坐标为高德坐标,默认:true
showButton: true, //显示定位按钮,默认:true
buttonPosition: 'LB', //定位按钮停靠位置,默认:'LB',左下角
buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
showMarker: true, //定位成功后在定位到的位置显示点标记,默认:true
showCircle: true, //定位成功后用圆圈表示定位精度范围,默认:true
panToLocation: true, //定位成功后将定位到的位置作为地图中心点,默认:true
zoomToAccuracy: true //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
});
// 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);
};
}
map.addControl(geolocation);
geolocation.getCurrentPosition();
AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
});
AMap.service('AMap.Geocoder',function(){//回调函数
//实例化Geocoder
geocoder = new AMap.Geocoder({
city: "000"//城市,默认:“全国”
});
//使用geocoder 对象完成相关功能
});
//解析定位结果
function onComplete(data) {
var address = df.value;
geocoder.getLocation(address, function(status, result) {
if (status === 'complete' && result.geocodes.length) {
var driving = new AMap.Driving({
map: map,
panel: "panel"
});
// 根据起终点经纬度规划驾车导航路线
driving.search(new AMap.LngLat(data.position.getLng(),data.position.getLat()),(result.geocodes[0].location));
}else{
//获取经纬度失败
}
});
}
//解析定位错误信息
function onError(data) {
document.getElementById('tip').innerHTML = '定位失败: <br/> <pre>' + JSON.stringify(data, null, 2) + '</pre>';
}
</script>