vue项目调用百度地图接口获取当前用户经纬度
// 从百度地图接口获取经纬度
getPosition2(callback) { let url = `//api.map.baidu.com/api?v=2.0&ak=${this.$config.resource.baiduAk}` this.$utils.jsonp.get(url).then(res => { // console.log("返回内容", res) let geolocation = new BMap.Geolocation(); geolocation.getCurrentPosition( r => { console.log(r.address, r.point) if (typeof callback === "function") { callback(r); } }, { //enableHighAccuracy表示是否允许使用高精度 enableHighAccuracy: true } ); }) },
上述代码中用到的jsonp函数参考:
https://www.jianshu.com/p/66fcfac9ea33?utm_campaign