1***@qq.com
1***@qq.com
  • 发布:2024-07-18 19:44
  • 更新:2024-07-18 20:25
  • 阅读:191

真机调试调用uni.getLocation,success或fail都不执行,只有complete执行

分类:nvue

const luxian = async() => {
markers.value=indexStore.markers
selectItem.value = indexStore.markers.find((p) => p.id == indexStore.markersIndex);
change_target();

await uni.getLocation({  
    type: 'gcj02',  
    success: async (res) => {  
        longitude.value = res.longitude;  
        latitude.value = res.latitude;  
        const result = await indexStore.useRoute_planning({ target: target.value.lon + ',' + target.value.lat, origin: longitude.value + ',' + latitude.value });  

        const distance = Math.round(result.data.distance / 100) / 10;  
        const title = distance + '公里   ' + Math.floor(result.data.duration / 60) + '分钟';  
        const targetObject = markers.value.find((p) => p.id === indexStore.markersIndex);  
        if (targetObject) {  
            // 执行修改操作  
            targetObject.callout = title;  
        } else {  
            console.error(`Object with id ${targetId} not found in markers array.`);  
        }  
        console.log(markers.value);  
        _mapContext.value.addMarkers({  
            markers: markers.value,  
            clear: true  
        });  
        console.log("执行")  

        polyline.value.points = result.data.polyline;  

        console.log('success结束');  
    },  
    fail: (e) => {  
        console.log('失败');  
        console.log('获取位置信息失败', e.errMsg);  
    },  
    complete: () => {  
        console.log(markers.value)  
        console.log('结束');  
    }  
});  

};
打印结果
[Object] [{"id":0,"latitude":28.32483,"longitude":112.935976,"iconPath":"/static/png/index/dian.png"...} at pages/index/luxian.nvue:289
结束 at pages/index/luxian.nvue:290 只执行complete
定位权限也提供了

2024-07-18 19:44 负责人:无 分享
已邀请:
m***@qq.com

m***@qq.com

测试

  • 1***@qq.com (作者)

    解决了谢谢

    2024-07-18 20:41

要回复问题请先登录注册