1***@qq.com
1***@qq.com
  • 发布:2025-11-14 09:27
  • 更新:2025-11-14 09:27
  • 阅读:25

uniappx为什么调用uni.onLocationChange不执行,uni.startLocationUpdate已经调用成功

分类:uni-app x
uni.startLocationUpdate({  
  type: 'wgs84',  
  success: () => {  
    console.log('开启定位成功')  
    statusText.value = '定位中...'  
    uni.showToast({  
      title: '开启定位成功',  
      icon: 'none'  
    })  
    // 监听位置变化  
    uni.onLocationChange((res) => {  
        uni.showToast({  
          title: '位置变化',  
          icon: 'none'  
        })  
        location.lat = res.latitude  
        location.lng = res.longitude  
        statusText.value = `定位成功 - 更新时间: ${new Date().toLocaleTimeString()}`  
        console.log('纬度:', res.latitude, '经度:', res.longitude)  
    })  

    // 监听定位错误  
    uni.onLocationChangeError((error) => {  
      console.error('定位错误:', error)  
      statusText.value = `定位错误: ${error.errMsg}`  
    })  

  },  
  fail: (err) => {  
    console.error('开启定位失败:', err)  
    statusText.value = '开启定位失败'  
  }  
})
2025-11-14 09:27 负责人:无 分享
已邀请:

要回复问题请先登录注册