Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda