//获取定位
//$(".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(‘用户拒绝授权获取地理位置‘,‘‘);
}
});
//});
本文详细介绍了如何在微信小程序中使用API获取用户的地理位置,并通过Ajax请求将经纬度转换为可读的地址信息。文中提供了具体的代码实现,包括事件监听、获取经纬度及地址解析的过程。

被折叠的 条评论
为什么被折叠?



