RN-地圖導(dǎo)航

調(diào)起百度網(wǎng)頁地圖路徑導(dǎo)航

    // 調(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&region=北京&output=html&src=yourCompanyName|yourAppName')

調(diào)起高德網(wǎng)頁地圖路徑導(dǎo)航

    // 調(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)航

    /*
    * 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: '鄭州'
                            });
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容