需求
- 小程序中有個按鈕點擊以后會調用手機中第三方地圖進行導航。
- 參數(shù) 位置信息 經(jīng)度 與緯度。
實現(xiàn)方法
uni.openLocation({
latitude: Number('地址緯度'),
longitude: Number('地址經(jīng)度'),
name: '地址名稱',
address: '地址詳情',
success: function (res) {
console.log('打開系統(tǒng)位置地圖成功')
},
fail: function (error) {
console.log(error)
}
原本以為一切順利,結果在微信開發(fā)者工具中顯示如下:
location參數(shù)格式錯誤,請正確填寫
經(jīng)過測試發(fā)現(xiàn),因為我在微信小程序中使用,所以默認會使用騰訊地圖來顯示。
而我的經(jīng)度和緯度的信息源開其他地圖軟件,格式上好像是不兼容的。
騰訊地圖獲取坐標點工具如下
https://lbs.qq.com/getPoint/
在這里獲取到的坐標點,就可以正常顯示了。
我的最終代碼如下:
uni.openLocation({
longitude: Number(118.797962),
latitude: Number(32.086816),
name: '南京站',
address: '江蘇省南京市玄武區(qū)龍蟠路',
success: function (res) {
console.log('打開系統(tǒng)位置地圖成功')
},
fail: function (error) {
console.log(error)
}
從明面上來看坐標的精度是保存小數(shù)點后6位
注意事項
latitude 緯度
longitude 經(jīng)度
不要搞返了,我一開始就搞返了
參考
uniapp下各端調用三方地圖導航
https://juejin.cn/post/7262941534528700453文章來源:http://www.zghlxwxcb.cn/news/detail-740245.html
https://uniapp.dcloud.net.cn/api/location/open-location.html文章來源地址http://www.zghlxwxcb.cn/news/detail-740245.html
到了這里,關于uni-app微信小程序打開第三方地圖的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!