Jared Norris 8 anni fa
parent
commit
97f55c47b9

+ 63
- 2
VueApp/src/components/GoogleMap.vue Vedi File

@@ -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>

+ 5
- 1
VueApp/src/components/Main.vue Vedi File

@@ -4,7 +4,7 @@
4 4
       <img src="http://via.placeholder.com/1000x100"/>
5 5
     </div>
6 6
     <div class="mainMap">
7
-      <img src="http://via.placeholder.com/500x500"/>
7
+      <google-map/>
8 8
     </div>
9 9
     <div class="infoGraphic">
10 10
       <img src="http://via.placeholder.com/800x100"/>
@@ -13,11 +13,15 @@
13 13
 </template>
14 14
 
15 15
 <script>
16
+  import GoogleMap from './GoogleMap.vue'
16 17
   export default {
17 18
     name: 'main',
18 19
     props: ['auth', 'authenticated'],
19 20
     beforeMount () {
20 21
       this.auth.login()
22
+    },
23
+    components: {
24
+      GoogleMap
21 25
     }
22 26
   }
23 27
 </script>

+ 8
- 0
VueApp/src/main.js Vedi File

@@ -1,11 +1,19 @@
1 1
 // The Vue build version to load with the `import` command
2 2
 // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 3
 import Vue from 'vue'
4
+import * as VueGoogleMaps from 'vue2-google-maps'
4 5
 import App from './App'
5 6
 import router from './router'
6 7
 
7 8
 Vue.config.productionTip = false
8 9
 
10
+Vue.use(VueGoogleMaps, {
11
+  load: {
12
+    key: 'AIzaSyDq8NHbKHAd2HE3SCtIpxq8yYVD16PzUlY',
13
+    libraries: 'places'
14
+  }
15
+})
16
+
9 17
 new Vue({ // eslint-disable-line no-new
10 18
   el: '#app',
11 19
   router,