This is my code:
<template>
<div>
<GmapMap id="map"/>
</div>
</template>
<script>
mounted(){
let map_div = document.getElementById("map");
let map = new google.maps.Map(map_div, { zoom: 15, center: { lat: 14.358723, lng: 120.788403 } })
**// THIS IS HOW I CREATE MARKER**
let marker = new google.maps.Marker({
position: { lat: 14.358723, lng: 120.788403 },
map: map,
icon: {
path: "<insert svg path>",
fillColor: "#43A047",
fillOpacity: 1,
strokeWeight: 2,
strokeOpacity: 0.6,
rotation: 0,
scale: .08,
anchor: new google.maps.Point(250, 250),
}
});
**// THIS IS HOW I SET MARKER DRAGGABLE**
marker.setDraggable(true)
}
</script>
Question: How can I use @drag function using mounted? PS: I already have a function for @drag which is to update coordinates of marker.
The Marker
class emits a drag
event . Instead of using Vue's @drag
(used in templates), you could add a listener to the Marker
's event programatically with the inherited addListener()
method :
let marker = new google.maps.Marker(...)
marker.addListener('drag', (e) => console.log('dragging'))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.