Skip to content

Instantly share code, notes, and snippets.

View DanielSmith's full-sized avatar
🖋️
Writing

Daniel Smith DanielSmith

🖋️
Writing
View GitHub Profile

Keybase proof

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:

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>
@DanielSmith
DanielSmith / eventbus.js
Created April 16, 2019 15:07
Simple Eventbus
/*
** 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) => {
@DanielSmith
DanielSmith / reverse-geocode-call.js
Last active April 16, 2019 15:18
Set up reverse geocoding
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;
@DanielSmith
DanielSmith / autocomplete-place-changed.js
Created April 16, 2019 15:25
Get autocomplete address and broadcast it
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
@DanielSmith
DanielSmith / receive-new-place.js
Created April 16, 2019 15:29
handle new address by updating map
updateFromTextAddress(payload) {
this.map.setCenter(payload.geometry.location);
this.updateMarker(payload.geometry.location);
},
@DanielSmith
DanielSmith / getCityState.js
Created April 17, 2019 18:44
Get city and state from location info
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);
@DanielSmith
DanielSmith / location-changed-event-handler.js
Created April 17, 2019 18:47
Location changed event handler
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);