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 = '开启定位失败'
}
})
1***@qq.com
- 发布:2025-11-14 09:27
- 更新:2025-11-14 09:27
- 阅读:25
0 个回复