高德API
使用方法:
getTitude() {
AMapLoader.load({
key: process.env.VUE_APP_AMAP_KEY,
version: '2.0',
plugins: ['AMap.Geolocation']
}).then(AMap => {
this.map = new AMap.Map(this.$refs.map, {
resizeEnable: true
})
let geolocation = new AMap.Geolocation({
enableHighAccuracy: true, //是否使用高精度定位,默认:true
timeout: 10000, //超过10秒后停止定位,默认:5s
position: 'RB', //定位按钮的停靠位置
buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
zoomToAccuracy: true //定位成功后是否自动调整地图视野到定位点
})
this.map.addControl(geolocation)
geolocation.getCurrentPosition((status, result) => {
if (status == 'complete') {
this.oilData.longitude = result.position.lng
this.oilData.latitude = result.position.lat
// 应该监听这四个数据 当全部存在时 执行
if(this.oilData.longitude && this.oilData.latitude && this.oilData.phone && this.startGet) {
this.init()
}
} else {
console.log('定位失败', result.message)
}
})
})
},
总结: 在app中高德地图定位经纬度API时间较长 约达一分钟 为了用户体验较好 建议结合app 让app去定位 然后把数据传给前端使用
版权声明:本文为weixin_43963309原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。