gpt4 book ai didi

google-maps - 在vue2-google-map中拖动后如何获取标记位置?

转载 作者:搜寻专家 更新时间:2023-10-30 22:14:06 26 4
gpt4 key购买 nike

我正在使用 vue2-google-map 库来显示带有标记的 map 。

<gmap-map ref="mymap" :center="mapStartLocation" :zoom="17" style="width: 100%; height: 300px">
<gmap-marker v-on:change="updateCoordinates()" :position="mapStartLocation" :draggable="true" @closeclick="updateCoordinates()"/>
</gmap-map>

这有效并将标记放在 mapStartLocation 的坐标上

用户在 map 上拖动标记后如何获取新坐标?

我尝试使用 @closeClick 和 v-on:change 但都没有注册。即使他们愿意,如何获取新坐标值的问题仍然存在。

有关如何使用此库进行操作的任何指示。documentation 中没有任何内容.

最佳答案

我发现 @drag 是最好的解决方案。但是,事件在用户拖动时发出,而不仅仅是在 @dragend 应该起作用之后 according to source-code ,但出于某种原因,我的情况并非如此。

<template>
<gmap-map ref="mymap" :center="mapStartLocation" :zoom="17" style="width: 100%; height: 300px">
<gmap-marker :position="mapStartLocation" :draggable="true" @drag="updateCoordinates" />
</gmap-map>
</template>

<script>
export default {
data() {
return {
coordinates: null,
}
},
methods: {
updateCoordinates(location) {
this.coordinates = {
lat: location.latLng.lat(),
lng: location.latLng.lng(),
};
},
},
}
</script>

关于google-maps - 在vue2-google-map中拖动后如何获取标记位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50314759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com