在作開發的時候,常常須要獲取用戶地址,在微信中比較省時間的方法是直接獲取用戶地址座標,下面這段代碼就是,直接拿去用吧!html
//獲取定位
//$(".getLocation").on("click", function(){
wx.getLocation({
type: 'gcj02', // 默認爲wgs84的gps座標,若是要返回直接給openLocation用的火星座標,可傳入'gcj02'
success: function (res) {
var latitude = res.latitude; // 緯度,浮點數,範圍爲90 ~ -90
var longitude = res.longitude; // 經度,浮點數,範圍爲180 ~ -180。
$("#p_LatLng").html(longitude+','+latitude); //用戶的座標
var url='GetAddress.asp?lat='+latitude+'&lng='+longitude;
$.ajax({
type:"get",
cache:false,
url:url,
success:function(res)
{
$("#p_Address").html(res); //中文地址
}
});
},
cancel: function (res) {
alert('用戶拒絕受權獲取地理位置','');
}
});
//});git
=======================================
學習交流微信:18611436777ajax