vue-google-maps
vue-google-maps copied to clipboard
Trigger @place_changed event of gmap-autocomplete manually
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.
I have the same issue. I tried using $emit('place_changed') by targeting the input using a custom $refs and it still fails.
Any news on this? I'm having the same problem :(
Also looking for a way to accomplish this.
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
}
})
})
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?