vue使用高德地圖根據(jù)坐標(biāo)定位點(diǎn)的實(shí)現(xiàn)代碼
前言
項(xiàng)目中需要根據(jù)坐標(biāo)定位,將自己的實(shí)現(xiàn)過程寫下來,廢話不多說,上代碼
正文
<script>
var map,marker;
export default {
data(){
return{
arriveCoor:[108.947025,34.2613255],//坐標(biāo)點(diǎn)
arrive:"",//位置信息
}
},
mounted() {
mapDraw(this.arriveCoor),
mapCoor(this.arriveCoor)
},
methods:{
mapDraw(arriveCoor){
map = new AMap.Map('map-location', { //map-location是嵌地圖div的id
resizeEnable: true, //是否監(jiān)控地圖容器尺寸變化
zoom:16, //初始化地圖層級(jí)
center: arriveCoor //初始化地圖中心點(diǎn)
});
// 定位點(diǎn)
this.addMarker(arriveCoor);
},
// 實(shí)例化點(diǎn)標(biāo)記
addMarker(arriveCoor) {
var _this = this;
marker = new AMap.Marker({
icon: "", //圖片ip
imageSize: "20px",
position: arriveCoor,
offset: new AMap.Pixel(-13, -30),
// 設(shè)置是否可以拖拽
draggable: true,
cursor: 'move',
// 設(shè)置拖拽效果
raiseOnDrag: true
});
marker.setMap(map);
},
// 查詢坐標(biāo)
mapCoor(lnglatXY){
var _this = this;
AMap.service('AMap.Geocoder',function() {//回調(diào)函數(shù)
var geocoder = new AMap.Geocoder({});
geocoder.getAddress(lnglatXY, function (status, result) {
if (status === 'complete' && result.info === 'OK') {
//獲得了有效的地址信息:
_this.arrive = result.regeocode.formattedAddress;
else {
_this.arrive = "暫無位置";
}
});
})
},
}
</script>
總結(jié)
以上所述是小編給大家介紹的vue使用高德地圖根據(jù)坐標(biāo)定位點(diǎn)的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
相關(guān)文章
vant遇到van-sidebar數(shù)據(jù)超出不能滑動(dòng)的問題
這篇文章主要介紹了vant遇到van-sidebar數(shù)據(jù)超出不能滑動(dòng)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
vue2.0+webpack環(huán)境的構(gòu)造過程
本文分步驟給大家介紹了vue2.0+webpack環(huán)境的構(gòu)造過程的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11
vue的v-if里實(shí)現(xiàn)調(diào)用函數(shù)
這篇文章主要介紹了vue的v-if里實(shí)現(xiàn)調(diào)用函數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
基于Vue3+TypeScript實(shí)現(xiàn)鼠標(biāo)框選功能
這篇文章主要介紹了基于Vue3+TypeScript實(shí)現(xiàn)鼠標(biāo)框選功能,文中通過代碼示例給大家講解的非常纖細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-07-07
為Vue3?組件標(biāo)注?TS?類型實(shí)例詳解
這篇文章主要為大家介紹了為Vue3?組件標(biāo)注?TS?類型實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08

