Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
Cannot read property 'lat' of undefined: Making vue2-google-maps add marker at click location

So I just want to add a map marker where the user clicks, but I can't seem to pass an event object from the google map to get the user's click location for placing a marker:

<template>
  <div>
    <GmapMap
  :center="center"
  :zoom="7"
  map-type-id="terrain"
  style="width: 90%; height: 400px"
  @click=this.mark(coords)
>
  <GmapMarker
    :key="index"
    v-for="(m, index) in markers"
    :position="m.position"
    :clickable="true"
    :draggable="true"
    @click="center=m.position"
  />
</GmapMap>
  </div>
</template>

<script>
import {gmapApi} from 'vue2-google-maps'
export default {
  computed: {
    google: gmapApi
  },
  data() {
    return {
      center: {lat: 40.66058758, lng: -111.8364045},
      markers: [],
      currentPlace: null
    };
  },
  mounted() {
    this.mark(event),
    this.$refs.mapRef.$mapPromise.then((map) => {
      
    })
  },
  name: 'Google Map',
  methods: {
    setPlace(place) {
      this.currentPlace = place;
    },
    mark(event) {
      this.markers = [
          {
              lat: event.lat,
              lng: event.lng,
              label: 'Marker'
          },
      ]
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>

This should just be a matter of getting "event" and passing it to the function, right?

This simply results in "Cannot read property 'lat' of undefined"

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda