Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!