vue + 高德地圖開發(fā)地圖選址及查看地址組件

選擇省市區(qū)填寫詳細地址進入點擊確認坐標打開地圖彈框

根據(jù)傳入的地址查詢到了地址可以查看更多地址,可以點擊地圖查看周邊,點擊確認,獲取坐標。

這是查看地址
??""?
????:close-on-click-modal="false"?
????:destroy-on-close="true"?
????:visible.sync="visibleVal"?
????:modal="modal"?width="800px"?
????class="x-ui-modal?map__dialog">
????"container">
????"poi__list"?ref="scrollWrap"?v-if="lists.length">
??????"ul">
????????"address-item"
??????????:class="nearbyIndex?===?choiceIndex???'active'?:?''"
[email protected]="choiceAddress(nearbyIndex)"?
??????????v-for="(nearby,?nearbyIndex)?in?lists"?:key="nearbyIndex">
??????????"icon">
??????????"text">
????????????"name"?:title="nearby.name">{{nearby.name?|?ellipsis}}
????????????"address"?:title="nearby.address">{{nearby.address?|?ellipsis}}
??????????
????????
????????"bottomLoadingShow">
????????"bottomLineShow">"'已無更多數(shù)據(jù),點擊地圖\n任意一處可以查看周邊'"/>
????????"moreShow"?@click="loadingMore">"'上拉或點我查看更多'"?style="cursor:?pointer;"?/>
??????
????
??????????v-if="isEdit"
??????class="city__name"
??????:title="`您查詢的${customerName???'客戶及地址'?:?'地址'}:${searchKwords}`">
??????????????v-model="searchKwords"
????????disabled?/>
????
????"isEdit">
??????"main__footer">
??????????????????@click="onCloseModal()"
??????????class="x-ui-btn?add__cancel"
??????????size="medium">取消
??????????????????@click="onSubmit()"
??????????class="x-ui-btn?add__submit"
??????????type="primary"
??????????size="medium">確認
??????
????
????
??????"main__footer">
??????????????????@click="onCloseModal()"
??????????class="x-ui-btn?add__cancel"
??????????size="medium">關(guān)閉
??????
????
??

interval()?{
??????this.timer?=?setInterval(function()?{
????????this.awaitPlaceSearch();
??????}.bind(this),?50)
????},
????awaitPlaceSearch()?{
??????if(this.placeSearch?&&?this.geoCoder)?{
????????clearInterval(this.timer);
????????this.isUseNearBy?=?false;
????????this.placeSearch.search(this.handleCityName,?(status,?result)?=>?{
??????????if?(status?===?'complete')?{
????????????if(result.poiList.pois.length)?{
??????????????if(result.poiList.pois.length?%?this.pageSize?!==?0)?{
????????????????this.isUseNearBy?=?true;
????????????????this.bottomLineShow?=?true;
??????????????}?else?{
????????????????this.isUseNearBy?=?false;
????????????????this.bottomLineShow?=?false;
??????????????}
??????????????const?geos?=?result.poiList.pois[0].location;
??????????????this.center?=?[geos.lng,?geos.lat];
??????????????this.getAreaInfo('location',?(res)?=>?{
????????????????this.lists?=?result.poiList.pois//將查詢到的地點賦值
????????????????this._initScroll();
????????????????this.getAddress(0);
????????????????this.createdMap([this.ruleForm.long,?this.ruleForm.lat]);
????????????????this.addMarker();
??????????????})
????????????}?else?{
??????????????if(result.cityList?&&?result.cityList.length?>?1)?{
????????????????this.lists?=?[];
????????????????this.onCloseModal();
????????????????this.$message.info(`當(dāng)前搜索地址在${result.cityList.length}個城市有若干結(jié)果,請明確后再搜索`);
??????????????}?else?{
????????????????this.lists?=?[];
????????????????this.onCloseModal();
????????????????this.$message.info('未能查詢到該地址,請更換關(guān)鍵字查詢');
??????????????}
????????????}
??????????}?else?if(status?===?'no_data')?{
????????????this.$message.warning(`您輸入的地址“${this.cityName}”,未查詢到相關(guān)信息`);
????????????this.getAreaInfo('address',?(res)?=>?{
??????????????this.lists?=?[
????????????????{
??????????????????location:?{
????????????????????lng:?res.geocodes[0].location.lng,
????????????????????lat:?res.geocodes[0].location.lat,
??????????????????},
??????????????????name:?res.geocodes[0].formattedAddress,
??????????????????address:?'',
????????????????}
??????????????]
??????????????this.center?=?[res.geocodes[0].location.lng,?res.geocodes[0].location.lat]
??????????????this._initScroll();
??????????????this.getAddress(0);
??????????????this.createdMap([this.ruleForm.long,?this.ruleForm.lat]);
??????????????this.addMarker();
??????????????this.isUseNearBy?=?true;
??????????????this.bottomLineShow?=?true;
????????????});
??????????}?else?{
????????????this.fixedPosition();//精準定位或IP地址定位
??????????}
????????})?
??????}
????},
//依賴高德該接口獲得省市區(qū)信息
????getAreaInfo(type,?callback)?{
??????if(type?===?'address')?{?//?在編輯的情況下通過地址名稱查詢
????????this.geoCoder.getLocation(this.handleCityName,?(status,?result)?=>?{
??????????if?(status?===?'complete'?&&?result.geocodes.length)?{
????????????this.ruleForm.regeocode.adcode?=?result.geocodes[0].adcode
????????????this.ruleForm.regeocode.province?=?result.geocodes[0].addressComponent.province
????????????this.ruleForm.regeocode.city?=?result.geocodes[0].addressComponent.city?==?''???result.geocodes[0].addressComponent.province?:?result.geocodes[0].addressComponent.city
????????????this.ruleForm.regeocode.district?=?result.geocodes[0].addressComponent.district;
????????????callback(result);
??????????}?else?if(status?===?'no_data')?{
????????????this.lists?=?[];
????????????this.onCloseModal();
????????????this.$message.info('未能查詢到該地址,請更換關(guān)鍵字查詢');
??????????}?else?{
????????????this.fixedPosition();//精準定位或IP地址定位
??????????}
????????});
??????}?else?if(type?===?'location')?{?//?在查看的情況下通過經(jīng)緯度查詢
????????this.geoCoder.getAddress(this.center,?(status,?result)?=>?{
??????????if?(status?===?'complete'?&&?result.regeocode?&&?result.regeocode.addressComponent)?{
????????????this.ruleForm.regeocode.adcode?=?result.regeocode.addressComponent.adcode
????????????this.ruleForm.regeocode.province?=?result.regeocode.addressComponent.province
????????????this.ruleForm.regeocode.city?=?result.regeocode.addressComponent.city?==?''???result.regeocode.addressComponent.province?:?result.regeocode.addressComponent.city
????????????this.ruleForm.regeocode.district?=?result.regeocode.addressComponent.district;
????????????callback(result);
??????????}?else?{
????????????this.fixedPosition();//精準定位或IP地址定位
??????????}
????????});
??????}
????},
//?查看更多,此方法也給上拉加載使用
searchMore(e)?{
??????if(e)?{
????????this.isUseNearBy?=?true;
????????this.placeSearch.opt.pageIndex?=?1;
????????this.center?=?[e.lnglat.getLng(),?e.lnglat.getLat()];
??????}?else?{
????????this.placeSearch.opt.pageIndex?+=?1;
??????}
??????this.geoCoder.getAddress(this.center,?(status,?result)?=>?{
????????if?(status?===?'complete'?&&?result.info?===?'OK')?{
??????????let?addressComponent?=?result.regeocode.addressComponent;
??????????this.ruleForm.regeocode.adcode?=?addressComponent.adcode
??????????this.ruleForm.regeocode.province?=?addressComponent.province
??????????this.ruleForm.regeocode.city?=?addressComponent.city?==?''???addressComponent.province?:?addressComponent.city
??????????this.ruleForm.regeocode.district?=?addressComponent.district;
??????????let?cityName?=?this.isUseNearBy???''?:?this.handleCityName;
??????????if(this.isUseNearBy)?{
????????????this.placeSearch.searchNearBy(cityName,?this.center,?1000,?(status,?result)?=>?{
??????????????this.searchCallBack(status,?result,?e)
????????????});
??????????}?else?{
????????????this.placeSearch.search(cityName,?(status,?result,?e)?=>?{
??????????????this.searchCallBack(status,?result)
????????????});
??????????}
????????}?else?{
??????????this.emptyLocationData();
????????}
??????})
????},
????searchCallBack(status,?result,?event)?{
??????if?(status?===?'complete'?&&?result.poiList.pois.length)?{
????????if(event)?{
??????????this.lists?=?result.poiList.pois;
??????????if(this.lists.length?%?this.pageSize?!==?0)?{
????????????this.bottomLineShow?=?true;
??????????}?else?{
????????????this.bottomLineShow?=?false;
??????????}
??????????this.getAddress(0);
??????????if(this.scroll)?{
????????????this.scroll.scrollTo(0,?0);
????????????this.scroll.finishPullUp();
??????????}?else?{
????????????this._initScroll();
??????????}
??????????this.addMarker();
????????}?else?{
??????????this.lists?=?concat(this.lists,?result.poiList.pois);
??????????if(this.lists.length?%?this.pageSize?!==?0)?{
????????????this.bottomLineShow?=?true;
??????????}?else?{
????????????this.bottomLineShow?=?false;
??????????}
??????????this.originalStatus();
????????}
??????}?else?{
????????this.bottomLineShow?=?true;
??????}
????},





評論
圖片
表情
