远程查女朋友手机定位(查一个人手机定位怎么查)效果:我在手机上打开微信小程序,自动显示出我当前所在的地理位置:
具体步骤:
1. 使用微信jssdk提供的getLocation API拿到经纬度;
2. 调用高德地图的api使用经纬度去换取地址的文字描述。
```javascript
wx.ready(() => {
wx.getLocation({
type: "gcj02",
success: function(res) {
var location =
"&location=" + res.longitude + "," + res.latitude;
ReservationService.getGeocode(location).then(response => {
if (
response.data.status === "1" &&
response.data.info === "OK"
) {
self.country =
response.data.regeocode.addressComponent.country;
self.city = response.data.regeocode.addressComponent.city;
var express =
"/" +
self.country +
"|" +
response.data.regeocode.addressComponent.province +
"|" +
self.city +
"|" +
response.data.regeocode.addressComponent.district +
"|" +
response.data.regeocode.addressComponent.township +
"/g";
self.address = response.data.regeocode.formatted_address.replace(
eval(express),
""
);
} else {
// get location error, plz input address
alert("无法获取地址信息,请稍后再试");
}
});
}
});
```
ReservationService.getGeocode的实现:
getGeocode(location) {
const key = '此处填入您高德地图app的key';
return axios.post('https://restapi.amap.com/v3/geocode/regeo?key=' + key + location);
}
看下面一个使用高德地图API将经纬度转换成文字描述的地址的例子,使用postman发送请求:
API响应:
```json
{
"status": "1",
"regeocode": {
"addressComponent": {
"city": [],
"province": "北京市",
"adcode": "110101",
"district": "东城区",
"towncode": "110101001000",
"streetNumber": {
"number": "44号",
"location": "116.39795,39.9097239",
"direction": "东北",
"distance": "117.874",
"street": "广场东侧路"