https://lbs.amap.com/api/javascript-api/guide/services/geolocation/?sug_index=1
瀏覽器定位
AMap.plugin('AMap.Geolocation', function() {
var geolocation = new AMap.Geolocation({
// 是否使用高精度定位垂涯,默認(rèn):true
enableHighAccuracy: true,
// 設(shè)置定位超時(shí)時(shí)間,默認(rèn):無窮大
timeout: 10000,
// 定位按鈕的推蛘ィ靠位置的偏移量,默認(rèn):Pixel(10, 20)
buttonOffset: new AMap.Pixel(10, 20),
// 定位成功后調(diào)整地圖視野范圍使定位位置及精度范圍視野內(nèi)可見,默認(rèn):false
zoomToAccuracy: true,
// 定位按鈕的排放位置, RB表示右下
buttonPosition: 'RB'
})
geolocation.getCurrentPosition()
AMap.event.addListener(geolocation, 'complete', onComplete)
AMap.event.addListener(geolocation, 'error', onError)
function onComplete (data) {
// data是具體的定位信息
}
function onError (data) {
// 定位出錯(cuò)
}
})