Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Google Places Autocomplete.
- Loading branch information
Showing
8 changed files
with
111 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
dist/ | ||
*.log | ||
secrets.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"development": { | ||
"GOOGLE_MAPS_API_KEY": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<template> | ||
<span class='search'> | ||
<input id='placeAutocomplete' type='text' v-model='place' /> | ||
<span class='bar'></span> | ||
</span> | ||
</template> | ||
|
||
<script> | ||
import MapsLoader from 'src/services/google_maps' | ||
MapsLoader.load(google => { | ||
const bounds = new google.maps.LatLngBounds( | ||
new google.maps.LatLng(20.3111981, -158.8405013), | ||
new google.maps.LatLng(22.2711981, -156.8005013) | ||
) | ||
const autocomplete = new google.maps.places.Autocomplete( | ||
document.getElementById('placeAutocomplete'), | ||
{ bounds, radius: 200, componentRestrictions: { country: 'us' } } | ||
) | ||
google.maps.event.addListener(autocomplete, 'place_changed', () => { | ||
console.log(autocomplete.getPlace()) | ||
}) | ||
}) | ||
export default { | ||
data () { | ||
return { | ||
place: '' | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.search { | ||
position: relative; | ||
margin: 25px 10px 25px; | ||
} | ||
.search input { | ||
font-size: 16px; | ||
padding-bottom: 5px; | ||
display: inline-block; | ||
width: calc(100% - 60px); | ||
border: none; | ||
border-bottom: 1px solid #757575; | ||
} | ||
.search input:focus { | ||
outline: none; | ||
} | ||
.search input:focus ~ label { | ||
top: -20px; | ||
font-size: 0.9rem; | ||
color: #2979FF; | ||
} | ||
.search input:focus ~ .bar:before, .search input:focus ~ .bar:after { | ||
width: 50%; | ||
} | ||
.bar { | ||
position: relative; | ||
display: block; | ||
width: calc(100% - 60px); | ||
} | ||
.bar:before, .bar:after { | ||
content: ''; | ||
height: 2px; | ||
width: 0; | ||
bottom: 4px; | ||
position: absolute; | ||
background: #2979FF; | ||
transition: 0.2s ease all; | ||
} | ||
.bar:before { | ||
left: calc(50% + 46px); | ||
} | ||
.bar:after { | ||
right: calc(50% - 46px); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* global __MAPS_KEY__:false */ | ||
import MapsLoader from 'google-maps' | ||
|
||
MapsLoader.KEY = __MAPS_KEY__ | ||
MapsLoader.LIBRARIES = ['places'] | ||
|
||
export default MapsLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters