高德地圖準確獲取當前位置資訊
阿新 • • 發佈:2019-01-08
mapObj = new AMap.Map('iCenter');
mapObj.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
});
mapObj.addControl(geolocation);
geolocation.getCurrentPosition();
AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位資訊
AMap.event.addListener(geolocation, 'error' , onError); //返回定位出錯資訊
});