|
|
@@ -1,11 +1,72 @@
|
|
1
|
1
|
<template>
|
|
|
2
|
+ <div>
|
|
|
3
|
+ <div>
|
|
|
4
|
+ <h2>Search and add a pin</h2>
|
|
|
5
|
+ <label>
|
|
|
6
|
+ <gmap-autocomplete
|
|
|
7
|
+ @place_changed="setPlace">
|
|
|
8
|
+ </gmap-autocomplete>
|
|
|
9
|
+ <button @click="addMarker">Add</button>
|
|
|
10
|
+ </label>
|
|
|
11
|
+ <br/>
|
|
2
|
12
|
|
|
|
13
|
+ </div>
|
|
|
14
|
+ <br>
|
|
|
15
|
+ <gmap-map
|
|
|
16
|
+ :center="center"
|
|
|
17
|
+ :zoom="12"
|
|
|
18
|
+ style="width:100%; height: 400px;"
|
|
|
19
|
+ >
|
|
|
20
|
+ <gmap-marker
|
|
|
21
|
+ :key="index"
|
|
|
22
|
+ v-for="(m, index) in markers"
|
|
|
23
|
+ :position="m.position"
|
|
|
24
|
+ @click="center=m.position"
|
|
|
25
|
+ ></gmap-marker>
|
|
|
26
|
+ </gmap-map>
|
|
|
27
|
+ </div>
|
|
3
|
28
|
</template>
|
|
4
|
29
|
|
|
5
|
30
|
<script>
|
|
6
|
|
- export default {
|
|
7
|
|
- name: "GoogleMap"
|
|
|
31
|
+ export default {
|
|
|
32
|
+ name: 'GoogleMap',
|
|
|
33
|
+ data () {
|
|
|
34
|
+ return {
|
|
|
35
|
+ center: { lat: 65.508, lng: -90.587 },
|
|
|
36
|
+ markers: [],
|
|
|
37
|
+ places: [],
|
|
|
38
|
+ currentPlace: null
|
|
|
39
|
+ }
|
|
|
40
|
+ },
|
|
|
41
|
+ methods: {
|
|
|
42
|
+ setPlace (place) {
|
|
|
43
|
+ this.currentPlace = place
|
|
|
44
|
+ },
|
|
|
45
|
+ addMarker () {
|
|
|
46
|
+ if (this.currentPlace) {
|
|
|
47
|
+ const marker = {
|
|
|
48
|
+ lat: this.currentPlace.geometry.location.lat(),
|
|
|
49
|
+ lng: this.currentPlace.geometry.location.lng()
|
|
|
50
|
+ }
|
|
|
51
|
+ this.markers.push({ position: marker })
|
|
|
52
|
+ this.places.push(this.currentPlace)
|
|
|
53
|
+ this.center = marker
|
|
|
54
|
+ this.currentPlace = null
|
|
|
55
|
+ }
|
|
|
56
|
+ },
|
|
|
57
|
+ geolocate: function () {
|
|
|
58
|
+ navigator.geolocation.getCurrentPosition(position => {
|
|
|
59
|
+ this.center = {
|
|
|
60
|
+ lat: position.coords.latitude,
|
|
|
61
|
+ lng: position.coords.longitude
|
|
|
62
|
+ }
|
|
|
63
|
+ })
|
|
|
64
|
+ }
|
|
|
65
|
+ },
|
|
|
66
|
+ mounted () {
|
|
|
67
|
+ this.geolocate()
|
|
8
|
68
|
}
|
|
|
69
|
+ }
|
|
9
|
70
|
</script>
|
|
10
|
71
|
|
|
11
|
72
|
<style scoped>
|