使用 uni.getLocation 和 uni.createMapContext(mapId,this) 都要在 manifest.json 中进行配置
image.png
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序定位"
}
},
"requiredPrivateInfos" : [ "getLocation", "chooseLocation" ],
使用
uni.getLocation:
uni.getLocation({
type: "gcj02", //默认为 wgs84 返回 gps 坐标
isHighAccuracy: true, // 开启高精度定位
success: e => {
console.log(e,'定位');
},fail:e=>{
console.log(e,'定位');
}
});
uni.createMapContext(mapId,this) :
注意在vue3 中没有 this 在onMounted 获取组件实例
onMounted(() => {
instance.value = getCurrentInstance();
});
uni.createMapContext("map", instance.value).moveToLocation({
latitude: val.location.lat,
longitude: val.location.lng //要数字类型
});