RN-地图导航
2018-05-29 本文已影响179人
精神病患者link常
调起百度网页地图路径导航
// 调起百度网页地图路径导航
//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=东城区赵府街51号&destination=广州市天河区黄埔大道中197号&mode=driving®ion=北京&output=html&src=yourCompanyName|yourAppName')
调起高德网页地图路径导航
// 调起高德网页地图路径导航
// 驾车: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调起百度APP地图路径导航
/*
* iOS调起百度APP地图路径导航
* */
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调起高德app地图路径导航
/*
* iOS调起高德APP地图路径导航
* */
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调起百度APP地图路径导航
/*
* Android调起百度APP地图路径导航
* */
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调起高德app地图路径导航
/*
* Android调起高德APP地图路径导航
* */
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: '郑州'
});