百度地图没有看到判断移动端有没有安装百度地图app的api的解决方案

百度地图没有看到判断移动端有没有安装百度地图app的api的解决方案

转载请注明预见才能遇见的博客:http://my.csdn.net/

原文地址:https://blog.csdn.net/pcaxb/article/details/84941387

            <div style={{display:''}} className='company-list-map-tonav'>
                <span onClick={()=>{this.toNavMap(this.state.itemData,1);}}>驾车导航</span>
                <span onClick={()=>{this.toNavMap(this.state.itemData,2);}}>骑行导航</span>
                <span onClick={()=>{this.toNavMap(this.state.itemData,3);}}>步行导航</span>
            </div>

 

    toNavMap(itemData,type){
        if(this.state.currentLat == 0){
            ToastShow('定位失败,重新定位中...');
            let geolocation = new BMap.Geolocation();
            let that = this;
            geolocation.getCurrentPosition(function (r) {
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                    //终点位置用的是接口中的orgName 不一定准确
                    that.setState({currentLat:r.point.lat,currentLng:r.point.lng});
                    that.toNavMap(itemData,type);
                }
                else {
                    alert('failed' + this.getStatus());
                }
            }, { enableHighAccuracy: true });
            return;
        }

        if (isAndroid) {
            let url = '';
            switch (type) {
                case 1:
                    url = "bdapp://map/navi?location="+itemData.markerLat+","+itemData.markerLng+"";
                    break;
                case 2:
                    url = "bdapp://map/bikenavi?origin="+this.state.currentLat+","+this.state.currentLng+"&destination="+itemData.markerLat+","+itemData.markerLng+"";
                    break;
                case 3:
                    //步行获取亮点之间的距离
                    var pointA = new BMap.Point(this.state.currentLat,this.state.currentLng);  // 创建点坐标A
                    var pointB = new BMap.Point(itemData.markerLat,itemData.markerLng);  // 创建点坐标B
                    //获取两点距离,保留小数点后两位
                    if(map.getDistance(pointA,pointB) > 100000){
                        ToastShow('距离太远,请更换其它方式!');
                        return;
                    }
                    url = "bdapp://map/walknavi?origin="+this.state.currentLat+","+this.state.currentLng+"&destination="+itemData.markerLat+","+itemData.markerLng+"";
                    break;
                default:
                    break;
            }
            var timeout = 600;
            let startTime = Date.now();
            let ifr = document.createElement('iframe');  
            ifr.src = url; 
            ifr.style.display = 'none';  
            document.body.appendChild(ifr);
            let t = setTimeout(function() {  
                let endTime = Date.now();
                if (!startTime || endTime - startTime < timeout + 200) {   
                    ToastShow('请先安装百度地图!');  
                }
            }, timeout);
            window.onblur = function() {  
                clearTimeout(t);  
            }            
        }else{
            
            ToastShow('还未开发');

            // let url = '';
            // switch (type) {
            //     case 1:
            //         // url = "bdapp://map/navi?location="+itemData.markerLat+","+itemData.markerLng+"";
            //         // url = "baidumap://map/navi?location"+itemData.markerLat+","+itemData.markerLng+""+
            //         // '&src=push&type=BLK&src=webapp.line.sjgy.sjgyepm';
    
            //         url = "baidumap://map/navi?location=40.057023, 116.307852&src=push&type=BLK&src=webapp.line.yourCompanyName.yourAppName";
            //         let aEle =  document.createElement('a');
            //         aEle.href = url;
            //         aEle.click();
                    
            //         break;
            //     case 2:
            //         url = "bdapp://map/bikenavi?origin="+this.state.currentLat+","+this.state.currentLng+"&destination="+itemData.markerLat+","+itemData.markerLng+"";
            //         break;
            //     case 3:
            //         //步行获取亮点之间的距离
            //         var pointA = new BMap.Point(this.state.currentLat,this.state.currentLng);  // 创建点坐标A
            //         var pointB = new BMap.Point(itemData.markerLat,itemData.markerLng);  // 创建点坐标B
            //         //获取两点距离,保留小数点后两位
            //         if(map.getDistance(pointA,pointB) > 100000){
            //             ToastShow('距离太远,请更换其它方式!');
            //             return;
            //         }
            //         url = "bdapp://map/walknavi?origin="+this.state.currentLat+","+this.state.currentLng+"&destination="+itemData.markerLat+","+itemData.markerLng+"";
            //         break;
            //     default:
            //         break;
            // }
        }

参考地址 :https://blog.csdn.net/a562550212/article/details/79239468

 

百度地图没有看到判断移动端有没有安装百度地图app的api的解决方案

博客地址:https://blog.csdn.net/pcaxb/article/details/84941387

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值