百度地图没有看到判断移动端有没有安装百度地图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的解决方案