H5 百度高德地图导航

H5 实现高德 百度 地图导航 可唤醒app

记住在引入高德地图

<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=高德key&plugin=AMap.Driving&plugin=AMap.ToolBar"></script>
//转百度坐标
 changeBd(gg_lng, gg_lat) {
      var X_PI = (Math.PI * 3000.0) / 180.0
      var x = gg_lng,
        y = gg_lat
      var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI)
      var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI)
      var bd_lng = z * Math.cos(theta) + 0.0065
      var bd_lat = z * Math.sin(theta) + 0.006
      return {
        lat: bd_lat,
        lng: bd_lng,
      }
    },
 //导航
  goMap(type) {
            var drivingOption = {
                policy: AMap.DrivingPolicy.LEAST_DISTANCE, // 其它policy参数请参考 https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingPolicy
                ferry: 1, // 是否可以使用轮渡
                province: "皖" // 车牌省份的汉字缩写
            };
            this.driving = new AMap.Driving(drivingOption);
            //0百度//1高德
            if (type == 0) {
                //godata目标地点名称
                let startBd = this.changeBd(this.startLng, this.startLat);
                let endBd = this.changeBd(this.endLng, this.endLat);
                location.href = `https://api.map.baidu.com/direction?origin=latlng:${startBd.lat},${startBd.lng}|name:我的位置&destination=latlng:${endBd.lat},${endBd.lng}|name:${this.godata}&mode=driving&region=合肥&output=html&src=yourCompanyName|yourAppName`;

                // console.log(href);
            } else {
                this.driving.search(
                    [this.startLng, this.startLat],
                    [this.endLng, this.endLat],
                    (status, result) => {
                        this.driving.searchOnAMAP({
                            origin: result.origin,
                            destination: result.destination
                        });
                    }
                );
            }
        },
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值