第一次寫,,,
1、適用于安卓 or ios (app端,小程式沒測驗)
2、注意點:
map組件的 @markertap 事件,并且 markers 里面的每一項必須要有id,用于區分標注的點和性能優化
3、@markertap這個事件可以拿到market的id,與標注點陣列的id相比較就可以拿到標注點的經緯度,至于怎么用可以看檔案(uniapp-map組件檔案)
4、代碼塊
@markertap這個事件可以拿到market的id,與標注點陣列的id相比較就可以拿到標注點的經緯度,至于怎么用可以看檔案
//呼叫打開地圖(需經度緯度和地址名稱,地址名稱是為了地圖展示搜索)
//經度緯度必須要,地圖會根據這個進行定位導航
this.toMapAPP(latitude,longitude,name)
//必須授權定位,且選擇地圖時會提示是否安裝了地圖app
openMapAPP(latitude,longitude,name){ //打開第三方地圖
let url = "";
if (plus.os.name == "Android") {//安卓端
plus.nativeUI.actionSheet({//選擇地圖
title: "選擇地圖",
cancel: "取消",
buttons: [{title: "騰訊地圖"},{title: "百度地圖"}, {title: "高德地圖"}]
}, function(e) {
switch (e.index) {
//下面是拼接url,不同系統以及不同地圖都有不同的拼接欄位
case 1:
//注意referer=xxx的xxx替換成你在騰訊地圖開發平臺申請的key
url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
break;
//默認支持coord_type=gcj02
case 2:
url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
break;
case 3:
url = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
break;
default:
break;
}
if (url != "") {
url = encodeURI(url);
//plus.runtime.openURL(url,function(e){})調起手機APP應用
plus.runtime.openURL(url, function(e) {
plus.nativeUI.alert("未安裝指定的地圖應用請前往應用市場安裝");
});
}
})
} else {
// iOS上獲取本機是否安裝了騰訊百度高德地圖,需要在manifest里配置,我的app暫時只支持高德地圖(其他的地圖會有很大偏差)
plus.nativeUI.actionSheet({
title: "選擇地圖",
cancel: "取消",
buttons: [{title: "騰訊地圖"},{title: "百度地圖"}, {title: "高德地圖"}]
}, function(e) {
switch (e.index) {
case 1:
url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
break;
//默認支持coord_type=gcj02
case 2:
url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
break;
case 3:
url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
break;
default:
break;
}
if (url != "") {
url = encodeURI(url);
plus.runtime.openURL(url, function(e) {
plus.nativeUI.alert("未安裝指定的地圖應用請前往appstore安裝");
});
}
})
}
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/292210.html
標籤:其他
