查询了好久都没有找到解决方法,弄好了分享一下.
高德文档:https://lbs.amap.com/api/java...
//这里要加window., loadScrpit的callback才会执行
window.mapInit = function(){
let mapObj = new AMap.Map('iCenter');
mapObj.plugin('AMap.Geolocation', function () {
let geolocation = new AMap.Geolocation({
enableHighAccuracy: false,//是否使用高精度定位,默认:true
timeout: 5000, //超过5秒后停止定位,默认:无穷大
});
mapObj.addControl(geolocation);
geolocation.getCurrentPosition();
//返回定位信息
AMap.event.addListener(geolocation, 'complete', function (res) {
console.log(res);
});
//返回定位出错信息
AMap.event.addListener(geolocation, 'error', function (err) {
console.log(err);
});
});
}
// 页面onload调用此方法
function loadScrpit(){
var script = document.createElement('script');
script.src = "https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值&callback=mapInit";
document.body.appendChild(script);
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。