当前位置:网站首页>Uniapp wechat applet calls mobile map to navigate to the target point

Uniapp wechat applet calls mobile map to navigate to the target point

2022-06-24 18:13:00 Gongsun yuaner

If your page has obtained the user's location permission , That's how it's written

 toAddress(position,positionAddress){
    
     let arr = position.split(',')
     const latitude = arr[0]
     const longitude = arr[1]
     console.log(' Call up the map :',arr)
     //  Open the map and navigate to the location 
     uni.openLocation({
    
         latitude: parseFloat(latitude),
         longitude: parseFloat(longitude),
         scale: 15,
         name: ' Destination ',
         address: positionAddress,
         success: res => {
    
             console.log(' Map opened successfully :', res)
         },
         fail: res => {
    
             console.log(' Failed to open map :', res)
         },
     })
 },

If not , It should be :

uni.getLocation({
    
    type: 'gcj02', // Return can be used for uni.openLocation Longitude and latitude of 
    success: function (res) {
    
        const latitude = res.latitude;
        const longitude = res.longitude;
        uni.openLocation({
    
            latitude: latitude,
            longitude: longitude,
            success: function () {
    
                console.log('success');
            }
        });
    }
});
原网站

版权声明
本文为[Gongsun yuaner]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211407077672.html