uni-app打开第三方地图软件进行导航
报错 wx.getLocation need to be declared in the requiredPrivateInfos field
解决 增加 "requiredPrivateInfos" : [ "getLocation" ]
<template>
<view class="page">
<map style="width: 100%; height: 300px;"
:latitude="startposition.lat"
:longitude="startposition.lng"
:markers="covers"
@markertap="openMap(startposition.lat,startposition.lng,'测试')"
>
</map>
<view class="content">
<map id="myMap" style="display: none;"/>
<button type="default" @click="openMap2">打开地图App</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
// 地图
startposition: {
lng: 123.054145,
lat: 41.160569
},
covers: [{
latitude: 41.160569,
longitude: 123.054145,
iconPath: "../../static/gonggao.png",
// iconPath: "../../static/map1.png",
label: {
content: 'Jeskson',
color: '#fff',
fontSize: 12,
borderRadius: 5,
padding: 5,
textAlign: 'center',
bgColor: '#2979ff',
},
}],
};
},
onLoad() {
},
onShow() {
},
onReachBottom(){
},
methods: {
// 打开的点击事件,传经纬度和地点名
openMap(latitude,longitude,name){
// 打开第三方 (小程序)
uni.getLocation({
success(res) {
uni.openLocation({
latitude: latitude,
longitude: longitude,
scale: 15
});
}
});
},
openMap2(){
let mapContext = uni.createMapContext("myMap");
mapContext.openMapApp({
latitude: 41.160569,
longitude: 123.054145,
destination: '测试',
success() {
console.log('success!!');
},
fail() {
console.log('fail!!');
},
complete() {
console.log('complete!!');
}
})
}
}
};
</script>
<style lang="scss">
page{
background: white;
}
</style>
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: