uniapp 腾讯地图定位不准解决方案 - 检查权限、定位方式和信号
可能是由于以下原因导致腾讯地图定位不准:
- 定位权限未开启或未被授权。
- 定位方式不正确,例如使用了基站定位或IP定位。
- 信号不好或者在室内等信号不好的地方。
以下是示例代码,可以尝试修改定位方式或检查定位权限是否已开启:
<template>
<view>
<map :longitude="longitude" :latitude="latitude" :scale="scale" :markers="markers" :show-location="true"></map>
</view>
</template>
<script>
export default {
data() {
return {
longitude: 0,
latitude: 0,
scale: 14,
markers: []
}
},
mounted() {
this.getLocation();
},
methods: {
getLocation() {
uni.getLocation({
type: 'gcj02',
success: (res) => {
this.longitude = res.longitude;
this.latitude = res.latitude;
this.markers = [{
id: 1,
longitude: res.longitude,
latitude: res.latitude,
title: '当前位置'
}]
},
fail: (res) => {
uni.showToast({
title: '获取位置失败',
icon: 'none'
});
}
})
}
}
}
</script>
原文地址: https://www.cveoy.top/t/topic/lMdj 著作权归作者所有。请勿转载和采集!