// 調(diào)起百度網(wǎng)頁地圖路徑導(dǎo)航
//mode: 固定為transit、driving、walking,分別表示公交、駕車和步行
baiduWebMap({startLon, startLat, startCity, endLon, endLat, endCity}){
let webUrl = `http://api.map.baidu.com/direction?origin=${startLat},${startLon}&destination=${endLat},${endLon}&origin_region=${startCity}&destination_region=${endCity}&mode=driving&output=html&src=yourCompanyName|yourAppName&coord_type=gcj02`;
Linking.openURL(webUrl).catch(e => console.warn(e));
},
Linking.openURL('http://api.map.baidu.com/direction?origin=東城區(qū)趙府街51號&destination=廣州市天河區(qū)黃埔大道中197號&mode=driving®ion=北京&output=html&src=yourCompanyName|yourAppName')
// 調(diào)起高德網(wǎng)頁地圖路徑導(dǎo)航
// 駕車:mode=car
// 公交: mode=bus
// 步行:mode=walk
// 騎行:mode=ride
gaodeWebMap(startLon, startLat, endLon, endLat){
let webUrl = `http://uri.amap.com/navigation?from=${startLon},${startLat},startpoint&to=${endLon},${endLat},endpoint&mode=car&policy=1&coordinate=gaode&callnative=0`;
return Linking.openURL(webUrl).catch(e => console.warn(e));
},
/*
* iOS調(diào)起百度APP地圖路徑導(dǎo)航
* */
baiduiOSAppMap({startLon, startLat, startCity, endLon, endLat, endCity}){
let appUrl = `baidumap://map/direction?origin=${startLat},${startLon}&destination=${endLat},${endLon}&mode=driving&origin_region=${startCity}&destination_region=${endCity}&coord_type=gcj02`;
Linking.canOpenURL(appUrl).then(supported => {
if (!supported) {
Toast.show('沒有安裝百度地圖')
} else {
return Linking.openURL(appUrl).catch(e => console.warn(e));
}
})
},
iOS調(diào)起高德app地圖路徑導(dǎo)航
/*
* iOS調(diào)起高德APP地圖路徑導(dǎo)航
* */
gaodeiOSAppMap({startLon, startLat, startCity, endLon, endLat, endCity}){
let appUrl = `iosamap://path?sourceApplication=applicationName&slat=${startLat}&slon=${startLon}&sname=${startCity}&dlat=${endLat}&dlon=${endLon}&dname=${endCity}&dev=0&m=0&t=0`;
Linking.canOpenURL(appUrl).then(supported => {
if (!supported) {
Toast.show('沒有安裝高德地圖')
} else {
return Linking.openURL(appUrl).catch(e => console.warn(e));
}
})
},
Android調(diào)起百度APP地圖路徑導(dǎo)航
/*
* Android調(diào)起百度APP地圖路徑導(dǎo)航
* */
baiduAndroidAppMap({startLon, startLat, startCity, endLon, endLat, endCity}){
let appUrl = `baidumap://map/direction?origin=${startLat},${startLon}&destination=${endLat},${endLon}&mode=driving&origin_region=${startCity}&destination_region=${endCity}&coord_type=gcj02`;
Linking.canOpenURL(appUrl).then(supported => {
if (!supported) {
Toast.show('沒有安裝百度地圖')
} else {
return Linking.openURL(appUrl).catch(e => console.warn(e));
}
})
},
Android調(diào)起高德app地圖路徑導(dǎo)航
/*
* Android調(diào)起高德APP地圖路徑導(dǎo)航
* */
gaodeAndroidAppMap({startLon, startLat, startCity, endLon, endLat, endCity}){
let appUrl = `androidamap://route?sourceApplication=applicationName&slat=${startLat}&slon=${startLon}&sname=${startCity}&dlat=${endLat}&dlon=${endLon}&dname=${endCity}&dev=0&m=0&t=0`;
Linking.canOpenURL(appUrl).then(supported => {
if (!supported) {
Toast.show('沒有安裝高德地圖')
} else {
return Linking.openURL(appUrl).catch(e => console.warn(e));
}
})
}
使用
MapUtil.baiduAndroidMap({
startLon: 121.48,
startLat: 31.22,
startCity: '上海',
endLon: 113.65,
endLat: 34.76,
endCity: '鄭州'
});