美文网首页
小程序/H5 利用高德地图API 获取当前位置信息

小程序/H5 利用高德地图API 获取当前位置信息

作者: waiterYu | 来源:发表于2020-03-21 12:03 被阅读0次

引入API文件

import amapFile from "../../utils/amap-wx";

调用

 getCityName() {
      var _this = this;
      var myAmapFun = new amapFile.AMapWX({
        key: "去高德地图获取key"
      });
      myAmapFun.getRegeo({
        success: function (data) {
          //成功回调
          console.log(data,1);
          // data[0].regeocodeData.formatted_address
          // _this.cityName = data[0].regeocodeData.formatted_address;
          _this.update({ cityName: data[0].regeocodeData.formatted_address });
        },
        fail: function (info) {
          //失败回调
          console.log(info);
          //如果用户拒绝授权
          // 默认为北京
          _this.cityName = "北京市";
          _this.update({ cityName: "北京市" });
        }
      });
    }
打印结果
image.png

相关文章

网友评论

      本文标题:小程序/H5 利用高德地图API 获取当前位置信息

      本文链接:https://www.haomeiwen.com/subject/rydyyhtx.html