在腾讯地图开放平台添加完应用以后将上面的KEY拿过来:
小程序进行调用腾讯的官方接口进行定位获取经纬度:
// 定位获取当前城市
getLocationLatLng: function(cb) {
var that = this;
app.globalData.getLocation(function(ret) {
if (ret) {
// 根据经纬度获取当前城市
functions.getAjaxData(
'https://你的接口地址', {
lat: ret.latitude,
lng: ret.longitude
},
function(res) {
uni.setStorageSync('locate_city', res.data);
if (res.data != that.now_city) {
that.now_city = res.data
uni.setStorageSync('now_lat', ret.latitude);
uni.setStorageSync('now_lng', ret.longitude);
uni.setStorageSync('now_city', res.data);
}
uni.navigateBack();
}
);
}
});
},
通过代码调用腾讯地图的SDK URL:
$return = http("https://apis.map.qq.com/ws/geocoder/v1/", [
'location' => "$lat,$lng",//此处为你小程序或者APP传递过来的经纬度
'key' => 你的KEY,
]);
$return = json_decode($return, true);
if (!$return['status']) {
$address = [
'prov' => $return['result']['address_component']['province'],
'city' => $return['result']['address_component']['city'],
];
}