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


    经纬度转地址信息

    // 逆地理编码,经纬度=》地址信息
    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);
          //将即将纬度存到本地
        }
      })
    });
    
  • 相关阅读:
    Neither BindingResult nor plain target object for bean name 'command' available as request attribute
    a href 相对路径 与绝对路径
    sql with as用法详解
    union和union all的区别
    从此不再惧怕URI编码:JavaScript及C# URI编码详解
    Server.UrlEncode、HttpUtility.UrlDecode的区别
    两种获取connectionString的方式
    微软SQLHelper.cs类 中文版
    web.config connectionStrings 数据库连接字符串的解释
    SQL Server 事务处理 回滚事务
  • 原文地址:https://www.cnblogs.com/fanzhen/p/12801750.html
Copyright © 2020-2023  润新知