//微信接口获取当前用户经纬度
var latitude, longitude;
wx.ready(function () {
// 获取用户位置
wx.getLocation({
success: function (res) {
//console.log('res', res)
latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
//调用百度接口 根据经纬度信息获取地址
$.ajax({
url: "https://api.map.baidu.com/geocoder/v2/?ak=2GhAjyOSR2zqbv2o4MaMIEHY3ieP1ixC&callback=renderReverse&location=" + latitude + "," + longitude + "&output=json&pois=1",
type: "get",
dataType: "jsonp",
jsonp: "callback",
success: function (data) {
var province = data.result.addressComponent.province;
var cityname = (data.result.addressComponent.city);
var district = data.result.addressComponent.district;
var street = data.result.addressComponent.street;
var street_number = data.result.addressComponent.street_number;
var address = data.result.formatted_address;
$('[name="address"]').val(province + cityname);
}
});
},
fail: function (res) {
//alert("获取位置失败");
}
});
});