7 changed files with 150 additions and 38 deletions
Split View
Diff Options
-
2app.js
-
6app.json
-
86components/city-change/index.js
-
16components/city-change/index.wxml
-
8components/city-change/index.wxss
-
69utils/map.js
-
1utils/qqmap-wx-jssdk.min.js
@ -0,0 +1,69 @@ |
|||
const wxqqmap = require('../utils/qqmap-wx-jssdk.min'), |
|||
qqwxmap = new wxqqmap({ |
|||
key: 'GAMBZ-CBGCK-GB6J3-A6PJX-F6ZHH-IWFUD' // 必填,这里最好填自己申请的的
|
|||
// key: 'NGOBZ-UL7ED-WJ34D-PMWW7-LBDI2-J5FYK'
|
|||
}); |
|||
export default class qqmap{//获取定位信息
|
|||
getLocateInfo(){ |
|||
let that=this; |
|||
return new Promise(function (resolve, reject) { |
|||
that.location().then(function(val){ |
|||
//如果通过授权,那么直接使用腾讯的微信小程序sdk获取当前定位城市
|
|||
qqwxmap.reverseGeocoder({ |
|||
location: { |
|||
latitude: val.latitude, |
|||
longitude: val.longitude |
|||
}, |
|||
success: function (res) { |
|||
console.log(res.result.address_component.city); |
|||
resolve(res.result.address_component.city);//返回城市
|
|||
}, |
|||
fail: function (res) { |
|||
reject(res); |
|||
}, |
|||
complete: function (res) { |
|||
console.log(res); |
|||
} |
|||
}); |
|||
|
|||
},function(error) { |
|||
//如果用户拒绝了授权,那么这里会提醒他,去授权后再定位
|
|||
console.log('shibai'); |
|||
wx.showModal({ |
|||
title: '', |
|||
content: '自动定位需要授权地理定位选项', |
|||
confirmText: '去授权', |
|||
success(res) { |
|||
if (res.confirm) { |
|||
wx.openSetting({ |
|||
success(res) { |
|||
console.log(res); |
|||
that.getLocateInfo(); |
|||
} |
|||
}) |
|||
} |
|||
} |
|||
}) |
|||
|
|||
}) |
|||
|
|||
}) |
|||
} |
|||
|
|||
//定位,获取当前经纬度
|
|||
location(){ |
|||
return new Promise(function (resolve, reject) { |
|||
wx.getLocation({ |
|||
altitude: true, |
|||
success: function (res) { |
|||
resolve(res); |
|||
},fail(res){ |
|||
reject(res); |
|||
} |
|||
}) |
|||
}); |
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
1
utils/qqmap-wx-jssdk.min.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save