1 //获取本人当前位置
2 function getCurrentPosition() {
3 var map = new AMap.Map("container", {
4 resizeEnable: true
5 });
6
7 map.plugin('AMap.Geolocation', function() {
8 geolocation = new AMap.Geolocation({});
9 geolocation.getCurrentPosition();
10 AMap.event.addListener(geolocation, 'complete', onComplete);
11 AMap.event.addListener(geolocation, 'error', onError);
12 });
13
14 function onComplete(data) {
15 //更新数据库中的本人当前位置
16 console.log(data)
17 }
18
19 function onError(data) {
20 alert("定位失败,请打开手机中的定位服务");
21 }
22 }