ios与安卓 调起第三方地图导航

<div id="map">

            </div>
            <div class="yb_choose_addr">
                <div class="shop_info">
                    <h5>小白汽车工厂店(郑州洛河路店)</h5>
                    <p><i class="iconfont icon-dingwei"></i>河南省郑州市中原区桐柏路与洛河路交叉口</p>
                    <span><i class="iconfont icon-dingwei"></i>营业时间:08:00-20:00</span>
                </div>
                <input type="button" name="" id="map_btn" value="确认" class="choose_btn" />
            </div>


mui.init();
        
        //选择门店  yb_choose_addr start 2019-10-18 王坚
        var _h = $(window).height();

        $("#map").css("height", _h - 60 + "px");

        var marker = null;
        var map = new BMap.Map("map"); // 创建地图实例  
        var point = new BMap.Point(113.665911, 34.750593); // 创建点坐标  
        map.centerAndZoom(point, 15);
        marker = new BMap.Marker(point);
        map.addOverlay(marker);

        $("#map_btn").on('tap', function() {

            var shop_name = info.shop_name;

            var point = bd_decrypt(113.665911, 34.750593);
            if(plus.os.name == "Android") {
                var bts = [{
                    title: "百度地图"
                }, {
                    title: "高德地图"
                }];
            } else if(plus.os.name == "iOS") {
                var bts = [{
                    title: "百度地图"
                }, {
                    title: "高德地图"
                }, {
                    title: "地图"
                }];
            }

            plus.nativeUI.actionSheet({
                    title: "选择地图",
                    cancel: "取消",
                    buttons: bts
                },
                function(e) {
                    if(e.index == 1) {
                        openBMap(longitude, latitude, shop_name);
                    } else if(e.index == 2) {
                        openAMap(point, shop_name);
                    } else if(e.index == 3) {
                        openMap(point, shop_name);
                    } else {
                        return false;
                    }
                }
            );
            return false;

        });

        function openMap(point, shop_name) {
            var url = "";
            switch(plus.os.name) {
                case "Android":
                    url = "geo:" + point.lat + "," + point.lng + "?q=" + shop_name;
                    break;
                case "iOS":
                    url = "http://maps.apple.com/?q=" + shop_name + "&ll=" + point.lat + "," + point.lng + "&spn=0.008766,0.019441";
                    break;
                default:
                    return;
                    break;
            }
            url = encodeURI(url);
            plus.runtime.openURL(url, function(e) {
                plus.nativeUI.alert("检查到您未安装地图程序\n");
            });
        }

        function openBMap(jingdu, weidu, shop_name) {
            var url = null,
                id = null,
                f = null;
            switch(plus.os.name) {
                case "Android":
                    // 规范参考官方网站:http://developer.baidu.com/map/index.php?title=uri/api/android
                    url = "baidumap://map/marker?location=" + weidu + "," + jingdu + "&title=" + shop_name + "&content=&悦车汇";
                    f = androidMarket;
                    id = "com.baidu.BaiduMap";
                    break;
                case "iOS":
                    // 规范参考官方网站:http://developer.baidu.com/map/index.php?title=uri/api/ios
                    url = "baidumap://map/marker?location=" + weidu + "," + jingdu + "&title=" + shop_name + "&content=悦车汇";
                    f = iosAppstore;
                    id = "itunes.apple.com/cn/app/bai-du-de-tu-yu-yin-dao-hang/id452186370?mt=8";
                    break;
                default:
                    return;
                    break;
            }
            url = encodeURI(url);
            plus.runtime.openURL(url, function(e) {
                plus.nativeUI.confirm("检查到您未安装\"百度地图\",是否到商城搜索下载?", function(i) {
                    if(i.index == 0) {
                        f(id);
                    }
                });
            });
        }

        function openAMap(point, shop_name) {
            var url = null,
                id = null,
                f = null;
            switch(plus.os.name) {
                case "Android":
                    // 规范参考官方网站:http://lbs.amap.com/api/uri-api/android-uri-explain/
                    url = "androidamap://viewMap?sourceApplication=悦车汇&poiname=" + shop_name + "&lat=" + point.lat + "&lon=" + point.lng + "&dev=0";
                    f = androidMarket;
                    id = "com.autonavi.minimap";
                    break;
                case "iOS":
                    // 规范参考官方网站:http://lbs.amap.com/api/uri-api/ios-uri-explain/
                    url = "iosamap://viewMap?sourceApplication=悦车汇&poiname=" + shop_name + "&lat=" + point.lat + "&lon=" + point.lng + "&dev=0";
                    f = iosAppstore;
                    id = "itunes.apple.com/cn/app/gao-tu-zhuan-ye-dao-hang-ban/id461703208?mt=8";
                    break;
                default:
                    return;
                    break;
            }
            url = encodeURI(url);
            plus.runtime.openURL(url, function(e) {
                plus.nativeUI.confirm("检查到您未安装\"高德地图\",是否到商城搜索下载?", function(i) {
                    if(i.index == 0) {
                        f(id);
                    }
                });
            }, id);
        }

猜你喜欢

转载自www.cnblogs.com/jiawenzhen/p/11881048.html
今日推荐