微信公众号里面使用地图导航

微信公众号实际上是h5页面,有些功能想要在微信中兼容性好,可以使用微信提供的jdk来实现。

微信页面不支持直接唤醒其他的地图app,但是可以使用openLocation间接的打开其他地图app。

 实例:从当前位置导航到你的目的地

在代码里引入微信提供的jdk,然后config你需要的功能函数,之后才能使用这些函数

//数据全部是通过接口获取到
wx.config({
    debug: false,// 开启调试模式,调用的所有api的返回值会在客户端alert出来
    appId: data.AppId,// 必填,公众号的唯一标识
    timestamp: data.Timestamp,// 必填,生成签名的时间戳
    nonceStr: data.NonceStr, //生成签名的随机串
    signature: data.Signature, //签名
    jsApiList: ['openLocation']// 必填,需要使用的JS接口列表
});
wx.openLocation({
    latitude: tlat,//目的地latitude
    longitude: tlng,//目的地longitude
    name: '江北机场T3航站楼',
    address: '重庆 江北机场T3航站楼',
    scale: 15//地图缩放大小,可根据情况具体调整
});

 注意:openLocation传入的坐标必须是火星坐标

//经纬度转换
function transformBD (lat, lng, type, callback) {
    var url;
   var self = this; if (type == 'gcj02') { //百度坐标转为火星坐标 url = "https://api.map.baidu.com/geoconv/v1/?coords=" + lng + "," + lat + "&from=5&to=3&ak=XXXXXXXXXX";//注意latitude 和longitude参数的顺序 } else { //'bd09ll' //转为百度坐标 url = "https://api.map.baidu.com/geoconv/v1/?coords=" + lng + "," + lat + "&from=1&to=5&ak=XXXXXXXXXXXXXX"; } $.ajax({ url: url, success: function (data, status, xhr) { if (status == 'success') { var point = data.result[0]; //y为lat,x为lng callback.call(self, point.y, point.x); } }, dataType: 'jsonp' }); }

  

流程:

使用openLocation打开微信自带的腾讯地图->选择右下角的绿色按钮->选择地图app,唤醒app会自动将你在openLocation中传入的目的地坐标带入

                                                      

 

posted @ 2018-10-16 17:03  abc1234_abc  阅读(19426)  评论(2编辑  收藏  举报