幾度設(shè)計網(wǎng)站軟文推廣新聞發(fā)布
需求
- 小程序中有個按鈕點擊以后會調(diào)用手機中第三方地圖進行導航。
- 參數(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)}
原本以為一切順利,結(jié)果在微信開發(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下各端調(diào)用三方地圖導航
https://juejin.cn/post/7262941534528700453
https://uniapp.dcloud.net.cn/api/location/open-location.html