I hereby claim:
- I am danielsmith on github.
- I am javajoint (https://keybase.io/javajoint) on keybase.
- I have a public key ASD2FvEZZ9y7E7lGgn7HaShBjiGLtAkNWAQZsMwcDBBWago
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
mounted: function() { | |
// targets for emitted events | |
eventBus.$on('googleInit', () => { | |
this.initMapAutocomplete(); | |
}); | |
eventBus.$on('mapAddress', (payload) => { | |
this.updateAddressFromMap(payload); | |
}); |
</v-layout> | |
<Map/> | |
</v-container> | |
</v-content> | |
</v-app> | |
</template> | |
<script> |
/* | |
** event-bus.js | |
*/ | |
import Vue from 'vue' | |
export const eventBus = new Vue({ | |
methods: {} | |
}); |
google.maps.event.addListener(this.map, "click", (event) => { | |
this.lastLat = event.latLng.lat(); | |
this.lastLng = event.latLng.lng(); | |
this.updateMarker(event.latLng); | |
this.geocoder.geocode({'location': event.latLng}, (results, status) => { |
google.maps.event.addListener(this.map, "click", (event) => { | |
this.lastLat = event.latLng.lat(); | |
this.lastLng = event.latLng.lng(); | |
this.updateMarker(event.latLng); | |
// stripped down example - needs error checking - we will fill this in | |
this.geocoder.geocode({'location': event.latLng}, (results, status) => { | |
// showing how you would grab the first address... | |
const firstAddress = results[0].formatted_address; |
initMapAutocomplete() { | |
this.geocoder = new google.maps.Geocoder(); | |
const input = document.getElementById('pac-input'); | |
const autocomplete = new google.maps.places.Autocomplete(input); | |
google.maps.event.addListener(autocomplete, 'place_changed', () => { | |
const place = autocomplete.getPlace(); | |
// we need to update the map |
updateFromTextAddress(payload) { | |
this.map.setCenter(payload.geometry.location); | |
this.updateMarker(payload.geometry.location); | |
}, |
cityStateHelper(str) { | |
let city = ''; | |
let state = ''; | |
if (!str) return ''; | |
const addressParts = str.split(','); | |
city = addressParts[0]; | |
// just the first two characters... | |
state = addressParts[1].trim().substring(0,2); |
google.maps.event.addListener(autocomplete, 'place_changed', () => { | |
this.curPlace = autocomplete.getPlace(); | |
this.theLocation = this.curPlace.formatted_address; | |
if (typeof this.curPlace.formatted_address !== "undefined") { | |
// parse the address to get city and state | |
this.cityState = this.cityStateHelper(this.curPlace.formatted_address); | |
// we need to update the map | |
eventBus.$emit('newTextAddress', this.curPlace); |