Open cassiehuang opened 5 years ago
const getPosition = cb => {
$.ajax({
url: 'http://api.map.baidu.com/location/ip?ak=ak&callback=showLocation',
dataType: 'jsonp', // 指定服务器返回的数据类型
success(res) {
cb(res);
},
});
};
export default getPosition;
const showPosition = (position) => { const map = new BMap.Map("allmap"); const point = new BMap.Point(position.coords.latitude, position.coords.longitude); map.centerAndZoom(point,12);
const geolocation = new BMap.Geolocation(); geolocation.getCurrentPosition(function(r){ if(this.getStatus() == BMAP_STATUS_SUCCESS){ var mk = new BMap.Marker(r.point); map.addOverlay(mk); map.panTo(r.point); alert('您的位置:'+r.point.lng+','+r.point.lat); } else { alert('failed'+this.getStatus()); } }); }