使用定位,逆地理编码,经纬度《=转=》地址信息、逆地理编码,地址《=转=》经纬度,贼方便!!!!

经纬度转地址信息

// 逆地理编码,经纬度=》地址信息
var lnglat = [lng, lat] AMap.plugin('AMap.Geocoder', function () {
  var geocoder = new AMap.Geocoder({
    city: '010',
    //城市设为北京,默认:“全国”
    radius: 1000,
    //范围,默认:500
    extensions: 'all',
  });
  geocoder.getAddress(lnglat, function (status, result) {
    if (status === 'complete' && result.info === 'OK') {
      // geocoder_CallBack(result);
      // console.log(result, "result");
      self.city = result.regeocode.addressComponent.city;
      self.resultData = result.regeocodeaddressComponent.city;
      localStorage.localCity = result.regeocode.addressComponent.city;
      localStorage.timestamp = new Date().getTime();
      localStorage.position = JSON.stringify(position);
      //将即将纬度存到本地
    }
  });
});

地址信息转经纬度

// 逆地理编码,地址-》经纬度
var address = '山东省苍山县';
//详细地址
AMap.plugin('AMap.Geocoder', function () {
  var geocoder = new AMap.Geocoder({
    city: '010',
    //城市设为北京,默认:“全国”
    radius: 1000,
    //范围,默认:500
    extensions: 'all'
  });
  geocoder.getAddress(address, function (status, result) {
    if (status === 'complete' && result.info === 'OK') {
      // geocoder_CallBack(result);
      // console.log(result, "result");
      self.city = result.regeocode.addressComponent.city;
      self.resultData = result.regeocode.addressComponent.city;
      localStorage.localCity = result.regeocode.addressComponent.city;
      localStorage.timestamp = new Date().getTime();
      localStorage.position = JSON.stringify(position);
      //将即将纬度存到本地
    }
  })
});
posted @ 2020-04-29 13:53  桢诚walker(逆行者)  阅读(228)  评论(0编辑  收藏  举报