diegoazh / gmap-vue

A wrapper component for consuming Google Maps API built on top of Vue. Fork of the popular vue-google-maps plugin.
https://diegoazh.github.io/gmap-vue/
173 stars 51 forks source link

Need help on: Using Geocoder with GMap #280

Closed jpschutte closed 1 year ago

jpschutte commented 2 years ago

Please complete all sections that you can but please don't remove any section, otherwise the bot will close your issue because it doesn't meet our issue template (you can remove this comment)

What you try to do

I would like to use the Google Maps Geocoder with the GMap component. I need to be able to use Geocoder within a click event on the GMap component. I'd like when a user clicks on the map, that Geocoder submits the coords and returns the physical address.

What is the problem

I can't figure out how to load Geocoder as there is no component in the docs.

What kind of things have you already treated

I have tried something like:

mounted () {
    this.$geocoder = new google.maps.Geocoder()
  },

  methods: {
    handleUpdatePosition (position) {
      this.$geocoder.geocode({
        location: {
          lat: position.latitude,
          lng: position.longitude
        }
      }).then(res => console.log('res', res))
    }
  }

However, I get an error: Error in mounted hook (Promise/async): "ReferenceError: google is not defined"

Steps to reproduce

Install gmap-vue plugin, load the GmapMap component and try to implement Geocoder.

Os

Mobile

Versions

Package manager

Plugin version

davydnorris commented 2 years ago

Make sure yo check the documentation before submitting a ticket - there's a whole section on this, with examples

https://diegoazh.github.io/gmap-vue/#accessing-google-maps-api