$(function() { var url = window.location.href; var userId = $("#userId").val(); // var openId = $("#sessionOpenId").val(); // alert("openId = " + openId); if ($("#path").val() != null && $("#path").val() != '' && typeof ($("#path").val()) != 'undefined') { if ($('#path').val().indexOf('msbh') != -1) { userId = $('#userId_share').val(); } } $.post("http://www.quanqiuyouhui.com/kabao-api/getShareData.do", { 'url' : url, 'userId' : userId }, function(data) { data = eval("(" + data + ")"); wx.config({ debug : false, appId : data.map.appId, timestamp : data.map.timestamp, nonceStr : data.map.nonceStr, signature : data.map.signature, jsApiList : [ 'checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'getLocation', 'openLocation', 'hideOptionMenu' ] }); wx.ready(function() { // 1 判斷當前版本是否支持指定 JS 接口,支持批量判斷 wx.checkJsApi({ jsApiList : [ 'getNetworkType', 'previewImage' ], success : function(res) { // 以鍵值對的形式返回,可用的api值true,不可用為false // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"} } }); wx.hideOptionMenu(); // 2. 分享接口 wx.getLocation({ type : 'wgs84', // 默認為wgs84的gps坐標,如果要返回直接給openLocation用的火星坐標,可傳入'gcj02' success : function(res) { // alert(JSON.stringify(res)); var latitude = res.latitude; // 緯度,浮點數,范圍為90 ~ -90 // $("#latitude").val(latitude); var longitude = res.longitude; // 經度,浮點數,范圍為180 ~ -180。 // $("#longitude").val(longitude); var speed = res.speed; // 速度,以米/每秒計 // $("#speed").val(speed); var accuracy = res.accuracy; // 位置精度 // $("#accuracy").val(accuracy); }, cancel : function(res) { alert('用戶拒絕授權獲取地理位置'); } }); // 2.1 監聽“分享給朋友”,按鈕點擊、自定義分享內容及分享結果接口 $(".icon").on('click', function() { //注意:因為蘋果手機默認瀏覽器將使用 attr('')獲得的信息默認為字符串格式所以不會打開地圖,需要先用parseFloat()將獲得的經緯度轉換一下如下 var a = $(this).attr("latitude");
a = parseFloat(a); var b = $(this).attr("longitude"); b = parseFloat(b); // alert(b); var c = $(this).attr("businessName"); // alert(c); var d = $(this).attr("address"); // alert(d); wx.openLocation({ latitude : a, longitude : b, name : c, address : d, scale : 14, infoUrl : 'http://www.quanqiuyouhui.com/kabao-api/pgyqr.do' }); }) // ---------------------------- }); }); });