vue使用高德地圖根據(jù)坐標(biāo)定位點(diǎn)的實(shí)現(xiàn)代碼
前言
項(xiàng)目中需要根據(jù)坐標(biāo)定位,將自己的實(shí)現(xiàn)過(guò)程寫(xiě)下來(lái),廢話不多說(shuō),上代碼
正文
<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 = "暫無(wú)位置";
}
});
})
},
}
</script>
總結(jié)
以上所述是小編給大家介紹的vue使用高德地圖根據(jù)坐標(biāo)定位點(diǎn)的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
相關(guān)文章
vue中使用百度腦圖kityminder-core二次開(kāi)發(fā)的實(shí)現(xiàn)
詳解vue+vuex+koa2開(kāi)發(fā)環(huán)境搭建及示例開(kāi)發(fā)
VUE前端從后臺(tái)請(qǐng)求過(guò)來(lái)的數(shù)據(jù)進(jìn)行轉(zhuǎn)換數(shù)據(jù)結(jié)構(gòu)操作
淺談Vue Element中Select下拉框選取值的問(wèn)題
vue深入解析之render function code詳解
vue踩坑記錄:屬性報(bào)undefined錯(cuò)誤問(wèn)題

