vue-google-maps
vue-google-maps copied to clipboard
Getting map center point after drag
I've got a whole load of markers so I'd like to dynamically load them in based upon the map center. However I don't see an elegant way to get this data.
Ideally the dragend event (and other drag events) on <GMapMap> should return the new center location data. Or is there a better way of doing this?
Theoretically, you ~bind~ model the center and then you have it. Or, at least as a user that is what I would expect. Can you confirm whether that is working?
Edit: v-model:center="center"
<template>
{{ center }}
<GMapMap :center="center" />
</template>
<script setup>
import { reactive } from "vue";
const center = reactive({ lat: 0, lng: 0 });
</script>
Nope, that didn't work. Thanks though.
I had a look through the code and found these events on the GMapMap component:
center_changed
zoom_changed
bounds_changed
Which also provides the relevant information as a callback. Hope this helps someone else in the future!
Oops - of course binding it wouldn't propagate the update back. I would still consider this an issue, because this should be available through v-model
here. With the power of Vue 3 v-model, there no longer needs to be any strange v-bind.sync
patterns going on when there is more than one value to model.