微信獲取地理位置

wx.config({

debug: false,

appId: "", // 必填,公眾號的唯一標(biāo)識

timestamp: "", //必填,生成簽名的時間戳

nonceStr: "", // 必填,生成簽名的隨機(jī)串

signature: "",// 必填,簽名,見附錄1

jsApiList: [ // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2

"getLocation",

"openLocation"

]

});

wx.ready(function(){

wx.getLocation({

type: 'wgs84', // 默認(rèn)為wgs84的gps坐標(biāo),如果要返回直接給openLocation用的火星坐標(biāo),可傳入'gcj02'

success: function (res) {

var latitude = res.latitude; // 緯度,浮點數(shù),范圍為90 ~ -90

var longitude = res.longitude; // 經(jīng)度,浮點數(shù),范圍為180 ~ -180。

var speed = res.speed; // 速度,以米/每秒計

var accuracy = res.accuracy; // 位置精度

$('#location').click(function(){

position(latitude,longitude);

})

//position(latitude,longitude);

}

});

});

function position(latitude,longitude){

$.ajax({

type:"",

url:"",

data: {

latitude:latitude,

longitude:longitude

},

async: false,

dataType:"json",

success:function(data){

x = data.position.x;

y = data.position.y;

}

})

var point = new BMap.Point(x,y);

// alert(point);

// map.centerAndZoom(point,12);

var geoc = new BMap.Geocoder();

var pt = point;

geoc.getLocation(pt, function(rs){

var addComp = rs.addressComponents;

var location = addComp.city + ", " + addComp.district + ", " + addComp.street;

$('#location').text(location);

// alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);

});

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容