Skip to content

How should I use the js code part "const bounds = new states.google.maps.LatLngBounds();" in this package ? #337

Discussion options

You must be logged in to vote

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

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@deidei1231
Comment options

Answer selected by HusamElbashir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #295 on June 28, 2025 01:58.