Commit c418a1dd4579516738ec13add8411d97ef731bbe

Authored by wangfan
1 parent c494e568

C端优化

@@ -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 })
@@ -249,7 +249,8 @@ class QQMapWX { @@ -249,7 +249,8 @@ class QQMapWX {
249 page_size: options.page_size || 10, 249 page_size: options.page_size || 10,
250 page_index: options.page_index || 1, 250 page_index: options.page_index || 1,
251 output: 'json', 251 output: 'json',
252 - key: that.key 252 + key: that.key,
  253 + region:options.region||'',
253 }; 254 };
254 255
255 if (options.address_format) { 256 if (options.address_format) {