How should I use the js code part "const bounds = new states.google.maps.LatLngBounds();" in this package ? #337
Answered
by
felixranesberger
deidei1231
asked this question in
Q&A
-
How should I use the js code part for exmaple "const bounds = new states.google.maps.LatLngBounds();" in this package ? |
Beta Was this translation helpful? Give feedback.
Answered by
felixranesberger
Jun 10, 2025
Replies: 1 comment 1 reply
-
This should help you fix your issue :) <script setup lang="ts">
import { GoogleMaps } from 'vue3-google-map'
const props = defineProps<{
markers: {
lat: number
lng: number
}[]
}>()
const mapInstance = ref<unknown | null>(null)
watch(() => mapInstance.value?.ready, (ready) => {
if (!ready)
return
const bounds = new window.google.maps.LatLngBounds()
props.markers.forEach((marker) => {
bounds.extend(marker)
})
const padding = 150
mapInstance.value.map.fitBounds(bounds, { top: padding, right: padding, bottom: padding, left: padding })
}, { immediate: true })
</script>
<template>
<GoogleMap
ref="mapInstance"
api-key=""
>
...
</GoogleMap>
</template> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
HusamElbashir
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should help you fix your issue :)