微信小程序获取当前所在城市
来源:互联网 发布:利达消防主机编程软件 编辑:程序博客网 时间:2024/06/05 09:29
data: {
imgs: [],
ak: "",//填写申请到的ak
province: '',
city: '',
district: '',
},
onLoad: function(options) {
this.getLocation();
},
getLocation: function() {
var that= this;
wx.getLocation({
type: 'wgs84',
success: function(res) {
var longitude= res.longitude;
var latitude= res.latitude;
that.loadCity(longitude,latitude);
}
});
},
loadCity: function(longitude,latitude) {
var that= this;
wx.request({
url: 'https://api.map.baidu.com/geocoder/v2/?ak='+ that.data.ak+ '&location='+ latitude + ','+ longitude+ '&output=json',
data: {},
header: {
'Content-Type':'application/json'
},
success: function(res) {
// success
console.log(res);
var province= res.data.result.addressComponent.province;
var city= res.data.result.addressComponent.city;
var district= res.data.result.addressComponent.district;
that.setData({
province: province,
city: city,
district: district,
});
},
fail: function() {
that.setData({city: "获取定位失败" });
},
})
},
阅读全文
0 0
- 微信小程序获取当前所在城市
- 微信小程序获取当前所在城市
- Winform-根据当前IP获取所在城市名称
- 通过javascript 获取当前地理位置 所在城市
- 【demo记录】百度地图获取当前所在城市
- 通过 GPS 信息获取当前所在城市名的代码
- 通过 GPS 信息获取当前所在城市名的代码
- 通过 GPS 信息获取当前所在城市名的代码
- 通过 GPS 信息获取当前所在城市名的代码
- WindowsPhone8 自动获取 ip 以及 当前所在城市信息
- iOS --- 使用CoreLocation获取当前所在城市等地理位置信息
- JS获取IP、IP所在城市、域名、完整URL、当前时间
- 微信小程序获取当前日期
- 微信小程序获取当前时间
- 用ip获取所在城市
- 获取用户所在城市信息
- IOS中定位当前所在城市
- 通过 GPS 信息获取当前所在城市名的代码 转自:hager的博客
- 超简单将Centos的yum源更换为国内的阿里云源
- HTML(十四)
- vidi电子产品缺陷检测软件外观检测自学习人工智能软件
- 8.10 Class类
- stm32 定时器
- 微信小程序获取当前所在城市
- LaTeX 入门文档
- Spring Boot 入门
- 无聊
- 什么是CDN
- 接触 cocos creator 的感受
- servlet的@WebServlet注解
- 插入排序
- 在 LaTeX 中为参考文献的标题编号