微信公衆號調用 導航而且計算當前位置距離目標點的距離
後臺調用jssdkjavascript
public static function jsSdk($url = '')
{
$apiList = ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'onVoicePlayEnd', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'translateVoice', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard'];
$jsService = self::jsService();java
if($url) $jsService->setUrl($url);
else $jsService->setUrl(request()->url(true));//公衆號的調用 小程序調用$jsService->setUrl(str_replace('http://','https://',request()->url(true)));
try{
return $jsService->config($apiList);
}catch (\Exception $e){
return '{}';
}git
}小程序
前臺:api
function goingTo(){
var lat=($('#lat').val()*100)/100;
var lng=($('#lng').val()*100)/100;
var se_name=$('#se_name').val();
var se_address=$('#se_address').val();
mapleWx($jssdk(),function(){
wx.openLocation({
longitude: lng,
latitude: lat,
name:se_name,
address: se_address
});微信
});
}ide
(function () {
mapleWx($jssdk(),function(){
//此處爲計算當前位置與目的位置的距離
wx.getLocation({
type: 'gcj02',
success: function (res) {
var radLat1 = res.latitude*Math.PI / 180.0;
var radLat2 = (($('#lat').val()*100)/100)*Math.PI / 180.0;
var a = radLat1 - radLat2;
var b = res.longitude*Math.PI / 180.0 - (($('#lng').val()*100)/100)*Math.PI / 180.0;
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
s = s *6378.137 ;// EARTH_RADIUS;
s = Math.round(s * 10000) / 10000;
$('#juli').text('距您'+s.toFixed(1)+'km');//#juli爲標籤的id
}
});this
});url
var shopsTabSpan = $('.shops-tab').find('span'),
shopsItem = $('.shops-item'),
_index = 0;spa
shopsItem.eq(_index).show(); shopsTabSpan.on('click', function () { $(this).addClass('active').siblings().removeClass('active') _index = $(this).index(); shopsItem.eq(_index).show().siblings().hide(); }) })();</script>記得調用 <script type="text/javascript" src="/public/static/plug/wxApi.js"></script>若小程序url爲https開頭,公衆號則爲http開頭