uni-app打开第三方地图软件进行导航

报错wx.getLocation need to be declared in the requiredPrivateInfos field
解决 增加"requiredPrivateInfos" : [ "getLocation" ]

uni-app打开第三方地图软件进行导航

<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 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!