vue + 高德地图开发地图选址及查看地址组件
SegmentFault
共 7939字,需浏览 16分钟
· 2020-12-24
选择省市区填写详细地址进入点击确认坐标打开地图弹框
根据传入的地址查询到了地址可以查看更多地址,可以点击地图查看周边,点击确认,获取坐标。
这是查看地址
""
: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' : ''"
@click.stop="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">"'已无更多数据,点击地图\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">关闭
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(`当前搜索地址在${result.cityList.length}个城市有若干结果,请明确后再搜索`);
} else {
this.lists = [];
this.onCloseModal();
this.$message.info('未能查询到该地址,请更换关键字查询');
}
}
} else if(status === 'no_data') {
this.$message.warning(`您输入的地址“${this.cityName}”,未查询到相关信息`);
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地址定位
}
})
}
},
//依赖高德该接口获得省市区信息
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('未能查询到该地址,请更换关键字查询');
} else {
this.fixedPosition();//精准定位或IP地址定位
}
});
} else if(type === 'location') { // 在查看的情况下通过经纬度查询
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;
}
},
评论
真高!比亚迪员工爆料比亚迪在越南的薪资水平:基本工资480万,全勤奖35万,交通补助20万,餐补110万,每周6天,每天10小时
上一篇:某大公司为逼迫员工离职,竟然把他的工位安排到厕所旁,没想到他直接开始记录领导的如厕时间,还发到公司大群...对此,你怎么看?--完--PS:欢迎在留言区留下你的观点,一起讨论提高。如果今天的文章让你有新的启发,欢迎转发分享给更多人。全文完,感谢你的耐心阅读。如果你还想看到我的文章,请一定给本
开发者全社区
0
为什么我们公司还在用 Python 开发项目?
作者:哇哒嘻哇https://www.zhihu.com/question/278798145/answer/3416549119最近几年里,经常看到某些曾重度使用 Python 的大公司迁移成其它语言技术栈,但是,那些小公司/小团队的情况如何呢?一直很想了解那些仍在坚持使用 Python,且支撑业
机器学习算法与Python实战
0
互联网晚报 | 大麦网已退款凤凰传奇演唱会“柱子票”;钟薛高再成被执行人;iPhone 16或取消实体音量键和电源键
大麦网回应凤凰传奇演唱会买到“柱子票”:已退票退款据报道,凤凰传奇2024巡回演唱会常州站演出结束的第二天,有网友称自己在大麦网买到“柱子票”,因为观看效果不佳,要求退款被拒。23日,记者从涉事网友处了解到,大麦方面给出了退款建议,但被其拒绝,“我希望平台退款加赔偿,并重视屡次出现的‘柱子票’问题。
产品刘
0
面试官:在原生input上面使用v-model和组件上面使用有什么区别?
前言面试官:vue3的v-model都用过吧,来讲讲。粉丝:v-model其实就是一个语法糖,在编译时v-model会被编译成:modelValue属性和@update:modelValue事件。一般在子组件中定义一个名为modelValue的props来接收父组件v-model传递的值,然后当子组
高级前端进阶
0
知乎高问:程序员有必要知道为什么做某个功能吗?
将Python客栈设为“星标⭐”第一时间收到最新资讯前言知乎上有一个提问:程序员有必要知道为什么做某个功能吗?↓↓↓今天,我们就这个话题一起来做个讨论。不知道程序员的你,在接到产品经理提的一个需求后,是习惯马上动手开始撸代码呢?还是会先暂停一下,认真思考一会如下一些问题,比如这个需求产生的背景是什么
Python客栈
0
乐普心安宝及心电图机,助力安康市搭建“心电一张网”,打通全域“生命线”!
为持续推动胸痛中心建设,助力全民健康,全面提升心血管疾病等急危重症救治能力水平。4月20日,由安康市卫健委主办、安康市中医医院承办的“第七届心血管汉江学术会议暨安康市胸痛中心大会”在高新国际会议中心顺利举行。市人大常委会主任王彪、市政协副主席唐纹、市政府党组成员刘英华等领导亲临现场,受邀参会的中国科
乐普医疗AI
0
【第124期】Vue 3 组合式 API 的瑞士军刀(VueUse)
概述 今天,我们要深入探索一个强大的工具集——VueUse。它为 Vue 3 的组合式 API(Composition API)提供了超过 200 个实用函数,让你的开发工作更加得心应手。官方网站:https://vueuse.org/VueUse 是什么?VueUse 的官方网站是 https:
前端微服务
0
面试官:你了解 QPS、TPS、RT、吞吐量 这些高并发性能指标吗?
大家好,我是路人,更多优质文章见个人博客:http://itsoku.com一、QPS,每秒查询QPS:Queries Per Second意思是“每秒查询率”,是一台服务器每秒能够相应的查询次数,是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准。互联网中,作为域名系统服务器的机器的性能
路人甲Java
0