分享

apicloud 打开外部地图APP

 看见就非常 2020-10-01
分类专栏: apicloud 文章标签: javascript 前端
最后发布:2020-05-19 15:50:36首次发布:2020-05-19 15:50:36
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

调用:

//打开导航
openMap({ //客户当前地址
    lon: _this.user_lng,
    lat: _this.user_lat,
    name: '起点'
},{ //店铺地址
    lon: _this.shop_lng,
    lat: _this.shop_lat,
    name: '终点'
});
/***打开外部地图APP
    @param {Object} start 起点信息(start.lon: 经度  start.lat: 维度  start.name: 位置信息)
    @param {Object} start 终点信息(end.lon: 经度  end.lat: 维度  end.name: 位置信息)
*/
function openMap(start = {}, end = {}){
    console.log(JSON.stringify(start));
    var navigator = api.require('navigator');
    if (api.systemType == 'android')
    {
        navigator.installed({ //判断用户是否安装百度地图
            target: 'bMap'
        }, function(ret, err) {
            if (ret.status)
            {
                console.log("已安装百度地图"+JSON.stringify(ret));
                navigator.bMapNavigation({ //打开百度地图APP
                    start: { // 起点信息.
                        lon: start.lon, // 经度.
                        lat: start.lat, // 纬度.
                        name: start.name //地址
                    },
                    end: { // 终点信息.
                        lon: end.lon, // 经度.
                        lat: end.lat, // 纬度.
                        name: end.name //地址
                    },
                    mode: 'driving'
                });
            }
            else
            {
                console.log("未安装百度地图"+JSON.stringify(err));
                // cui.confirm({
                //     title: "提示",
                //     content: "检测到您的手机尚未安装百度地图客户端,是否去安装",
                //     mask: true,
                //     maskTouch: true,
                //     btns: [{name: '取消'}, {name: '确定'}],
                // },function(e){
                //     if(e.index == 1){
                //         var url = "http://map.baidu.com/zt/client/index/";
                //         // var url = "http://map.baidu.com/zt/qudao/newfengchao/1012337a/html/slide.html";
                //         openWin('web_page','../home/web_page.html',{'url': url, "title": "返回"});
                //     }
                // });
                // return false;
                navigator.installed({ //判断用户是否安装高德地图APP
                    target: 'aMap'
                }, function(ret, err) {
                    if (ret.status)
                    {
                        console.log("已安装高德地图"+JSON.stringify(ret));
                        navigator.aMapNavigation({
                            start: { // 起点信息.
                                lon: start.lon, // 经度.
                                lat: start.lat, // 纬度.
                                name: start.name //地址
                            },
                            end: { // 终点信息.
                                lon: end.lon, // 经度.
                                lat: end.lat, // 纬度.
                                name: end.name //地址
                            },
                            dev: 0,
                            strategy: 'fast'
                        });
                    }
                    else
                    {
                        console.log("未安装高德地图"+JSON.stringify(err));
                        cui.confirm({
                            title: "提示",
                            content: "检测到您的手机尚未安装百度地图客户端,是否去安装",
                            mask: true,
                            maskTouch: true,
                            btns: [{name: '取消'}, {name: '确定'}],
                        },function(e){
                            if(e.index == 1){
                                var url = "http://map.baidu.com/zt/client/index/";
                                // var url = "http://map.baidu.com/zt/qudao/newfengchao/1012337a/html/slide.html";
                                openWin('web_page','../home/web_page.html',{'url': url, "title": "返回"});
                            }
                        });
                    }
                });
            }
        });
    }
    else
    { //ios打开自带地图导航
        navigator.appleNavigation({
            start: { // 起点信息.
                lon: start.lon, // 经度.
                lat: start.lat, // 纬度.
                name: start.name //地址
            },
            end: { // 终点信息.
                lon: end.lon, // 经度.
                lat: end.lat, // 纬度.
                name: end.name //地址
            },
            mode: 'driving'
        });
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多