forked from xkjyeah/vue-google-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocomplete.html
73 lines (66 loc) · 1.7 KB
/
autocomplete.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<body>
<div id="root">
<h1>Autocomplete Example (#164)</h1>
<label>
AutoComplete
<gmap-autocomplete
placeholder="This is a placeholder text"
@place_changed="setPlace">
</gmap-autocomplete>
<button @click="usePlace">Add</button>
</label>
<br/>
<Gmap-Map style="width: 600px; height: 300px;" :zoom="1" :center="{lat: 0, lng: 0}">
<Gmap-Marker v-for="(marker, index) in markers"
:key="index"
:position="marker.position"
></Gmap-Marker>
<Gmap-Marker
v-if="this.place"
label="★"
:position="{
lat: this.place.geometry.location.lat(),
lng: this.place.geometry.location.lng(),
}"
></Gmap-Marker>
</Gmap-Map>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="vue-google-maps.js"></script>
<script>
Vue.use(VueGoogleMaps, {
load: {
key: 'AIzaSyDf43lPdwlF98RCBsJOFNKOkoEjkwxb5Sc',
libraries: 'places'
},
});
document.addEventListener('DOMContentLoaded', function() {
new Vue({
el: '#root',
data: {
markers: [],
place: null,
},
methods: {
setDescription(description) {
this.description = description;
},
setPlace(place) {
this.place = place
},
usePlace(place) {
if (this.place) {
this.markers.push({
position: {
lat: this.place.geometry.location.lat(),
lng: this.place.geometry.location.lng(),
}
})
this.place = null;
}
}
}
});
});
</script>
</body>