获取地址、城市

uni.getSetting({

success(res) { 

if (!res.authSetting['scope.userLocation']) {

// 未授权

uni.authorize({

scope: 'scope.userLocation',

success() { //1.1 允许授权

  uni.getLocation({

type: 'gcj02',

geocode:true,//设置该参数为true可直接获取经纬度及城市信息

success: function (res) {

uni.setStorageSync("locationLat",res.latitude)

uni.setStorageSync("locationLng",res.longitude)

uni.request({

  url: 'http://api.map.baidu.com/reverse_geocoding/v3/?ak=Tolbv6WmfNq8bMNaT729T9sxuGRoysYH&location=' + res.latitude + ',' + res.longitude + '&output=json',

  data: {},

  header: {

    'Content-Type': 'application/json'

  },

  success: function (res) {

  if(res.data.status == 0){

  uni.setStorageSync("city_name",res.data.result.addressComponent.city)

  that.nvConfig.address.county = res.data.result.addressComponent.city


  uni.setStorageSync("index_province_name",res.data.result.addressComponent.province)

  uni.setStorageSync("index_city_name",res.data.result.addressComponent.city)

  that.getdata()

  that.loadData(1);

  }

  },

})

},

  });

},


})

}

that.getdata()

}

});

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容