vue-google-maps icon indicating copy to clipboard operation
vue-google-maps copied to clipboard

Trigger @place_changed event of gmap-autocomplete manually

Open 5T0NkZ5V2j0H76y0 opened this issue 6 years ago • 5 comments

I'm passing a string from database to gmap-autocomplete component. But place isn't set. When I validate the very form, it doesn't pass because place is empty. I should be able to trigger setPlace somehow manually, without the user interacting with the gmap-autocomplete input.

Thanks in advance.

5T0NkZ5V2j0H76y0 avatar Jul 16 '18 10:07 5T0NkZ5V2j0H76y0

I have the same issue. I tried using $emit('place_changed') by targeting the input using a custom $refs and it still fails.

SimonDesautels avatar Jul 26 '18 13:07 SimonDesautels

Any news on this? I'm having the same problem :(

JackEdwardLyons avatar Jul 10 '19 01:07 JackEdwardLyons

Also looking for a way to accomplish this.

Fingel avatar Mar 30 '20 22:03 Fingel

If you're like me, what you actually want to do is just call the geocoding function from the google javascript api and use the result to do something else in the component. You can import the the google maps api directly:

import {gmapApi} from 'vue2-google-maps'

Add google to your computed properties:

computed: {
    google: gmapApi
}

Now you can use the geocoding API directly using the secret this.$gmapApiPromiseLazy({}) promise :

this.$gmapApiPromiseLazy({}).then(() => {
  var geocoder = new this.google.maps.Geocoder()
  geocoder.geocode({'address': this.form.address}, (result, status) => {
    if(status == 'OK'){
      this.setPlace(result[0]) // do something with the first result
    }
  })
})

Fingel avatar Mar 31 '20 00:03 Fingel

Uncaught (in promise) TypeError: Cannot read property 'gmapApi' of null at VueComponent.gmapApi (main.js?755e:191) at Watcher.get (vue.runtime.esm.js?2b0e:4479) at Watcher.evaluate (vue.runtime.esm.js?2b0e:4584) at VueComponent.computedGetter [as google] (vue.runtime.esm.js?2b0e:4836) at eval (Mapa.vue?57cc:86)

what am I doing wrong?

darkducke avatar Oct 30 '20 14:10 darkducke