|
@@ -23,6 +23,7 @@ Page({ |
|
@@ -23,6 +23,7 @@ Page({ |
|
23
|
*/
|
23
|
*/
|
|
24
|
onLoad: function (options) {
|
24
|
onLoad: function (options) {
|
|
25
|
this.getHistory();
|
25
|
this.getHistory();
|
|
|
|
26
|
+ this.getPos()
|
|
26
|
},
|
27
|
},
|
|
27
|
|
28
|
|
|
28
|
/**
|
29
|
/**
|
|
@@ -122,7 +123,8 @@ Page({ |
|
@@ -122,7 +123,8 @@ Page({ |
|
122
|
qqmapsdk.getSuggestion({
|
123
|
qqmapsdk.getSuggestion({
|
|
123
|
//获取输入框值并设置keyword参数
|
124
|
//获取输入框值并设置keyword参数
|
|
124
|
keyword: e.detail.value, //用户输入的关键词,可设置固定值,如keyword:'KFC'
|
125
|
keyword: e.detail.value, //用户输入的关键词,可设置固定值,如keyword:'KFC'
|
|
125
|
- //region:'北京', //设置城市名,限制关键词所示的地域范围,非必填参数
|
126
|
+ region:this.location.city||'', //设置城市名,限制关键词所示的地域范围,非必填参数
|
|
|
|
127
|
+ //region_fix:1,//锁定在本市
|
|
126
|
success: function (res) {//搜索成功后的回调
|
128
|
success: function (res) {//搜索成功后的回调
|
|
127
|
console.log(res);
|
129
|
console.log(res);
|
|
128
|
var sug = [];
|
130
|
var sug = [];
|
|
@@ -161,6 +163,7 @@ Page({ |
|
@@ -161,6 +163,7 @@ Page({ |
|
161
|
}
|
163
|
}
|
|
162
|
qqmapsdk.search({
|
164
|
qqmapsdk.search({
|
|
163
|
keyword: this.inputVal, //搜索关键词
|
165
|
keyword: this.inputVal, //搜索关键词
|
|
|
|
166
|
+ region:this.location.city||'', //设置城市名,限制关键词所示的地域范围,非必填参数
|
|
164
|
page_size:20,
|
167
|
page_size:20,
|
|
165
|
location:location,
|
168
|
location:location,
|
|
166
|
success: function (res) { //搜索成功后的回调
|
169
|
success: function (res) { //搜索成功后的回调
|
|
@@ -188,4 +191,52 @@ Page({ |
|
@@ -188,4 +191,52 @@ Page({ |
|
188
|
}
|
191
|
}
|
|
189
|
});
|
192
|
});
|
|
190
|
},
|
193
|
},
|
|
|
|
194
|
+ location:'',
|
|
|
|
195
|
+ getPos(){
|
|
|
|
196
|
+ this._getPos().then(res => {
|
|
|
|
197
|
+ console.log('wx.getLocation.then', res);
|
|
|
|
198
|
+ this.location=res
|
|
|
|
199
|
+ this.getCity()
|
|
|
|
200
|
+ }).catch((e) => {
|
|
|
|
201
|
+ console.log('wx.getLocation.catch', e);
|
|
|
|
202
|
+ if ('getLocation:fail auth deny' == e.errMsg || 'getLocation:fail:auth denied' == e.errMsg) {
|
|
|
|
203
|
+ this.selectComponent('#showModal').options({
|
|
|
|
204
|
+ header: '定位失败',
|
|
|
|
205
|
+ body: '需要地理位置授权'
|
|
|
|
206
|
+ }).show();
|
|
|
|
207
|
+ } else {
|
|
|
|
208
|
+ setTimeout(() => {
|
|
|
|
209
|
+ this.getPos()
|
|
|
|
210
|
+ }, 500)
|
|
|
|
211
|
+ }
|
|
|
|
212
|
+
|
|
|
|
213
|
+ })
|
|
|
|
214
|
+ },
|
|
|
|
215
|
+ _getPos(){
|
|
|
|
216
|
+ return new Promise((success, fail) => {
|
|
|
|
217
|
+ wx.getLocation({
|
|
|
|
218
|
+ type: 'gcj02',
|
|
|
|
219
|
+ success: (res) => {
|
|
|
|
220
|
+ success(res)
|
|
|
|
221
|
+ },
|
|
|
|
222
|
+ fail: (res) => {
|
|
|
|
223
|
+ fail(res)
|
|
|
|
224
|
+ },
|
|
|
|
225
|
+ complete: (res) => {
|
|
|
|
226
|
+ console.log('wx.getLocation', res)
|
|
|
|
227
|
+ }
|
|
|
|
228
|
+ });
|
|
|
|
229
|
+ })
|
|
|
|
230
|
+ },
|
|
|
|
231
|
+ getCity(){
|
|
|
|
232
|
+ qqmapsdk.reverseGeocoder({
|
|
|
|
233
|
+ location:this.location,
|
|
|
|
234
|
+ success:(res)=>{
|
|
|
|
235
|
+ this.location['city']='';
|
|
|
|
236
|
+ if(res.status==0){
|
|
|
|
237
|
+ this.location['city']=res.result.ad_info.city
|
|
|
|
238
|
+ }
|
|
|
|
239
|
+ },
|
|
|
|
240
|
+ })
|
|
|
|
241
|
+ }
|
|
191
|
}) |
242
|
}) |