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

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

微信页面不支持直接唤醒其余的地图app,可是能够使用openLocation间接的打开其余地图app。ajax

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

在代码里引入微信提供的jdk,而后config你须要的功能函数,以后才能使用这些函数api

//数据所有是经过接口获取到
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' }); }

  

流程:app

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

                                                      

相关文章
相关标签/搜索