高德 api http://lbs.amap.com/api/javascript-api/summary
var map, geolocation;
function getLocation() {
try {
//加载地图,调用浏览器定位服务
map = new AMap.Map('iCenter');
map.plugin('AMap.Geolocation', function () {
geolocation = new AMap.Geolocation({
timeout: 10000, //超过10秒后停止定位
});
map.addControl(geolocation);
geolocation.getCurrentPosition();
AMap.event.addListener(geolocation, 'complete', handleMapData);
AMap.event.addListener(geolocation, 'error', handleMapData);
});
} catch (e) {
}
}
function handleMapData(dt) {
if (dt.type == 'complete') {
vm.location = handleLocation(
{
province: dt.addressComponent.province,
city: !_.isEmpty(dt.addressComponent.city) ? dt.addressComponent.city : '',
district: ''
}
);
}
// resetShowList();
}
参考 https://www.cnblogs.com/milkmap/p/3834039.html