Skip to content

Commit e5a889f

Browse files
authored
Create how-to-access-google-maps-object.md
1 parent 12da234 commit e5a889f

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# How to access Google Maps object.
2+
3+
[Interactive example on Condesandbox](https://stackblitz.com/edit/vue-google-maps-marker-khyhfk?file=src/components/ComponentWithMap.vue)
4+
5+
6+
To access Google maps object, or do something when map is loaded, use a ref on the `GMapMap` object.
7+
8+
9+
## Example
10+
11+
```bash
12+
<template>
13+
<GMapMap
14+
:center="center"
15+
ref="myMapRef"
16+
:zoom="10"
17+
map-type-id="terrain"
18+
style="width: 100vw; height: 20rem"
19+
>
20+
<GMapCluster :zoomOnClick="true">
21+
<GMapMarker
22+
:key="index"
23+
v-for="(m, index) in markers"
24+
:position="m.position"
25+
:clickable="true"
26+
:draggable="true"
27+
@click="center = m.position"
28+
/>
29+
</GMapCluster>
30+
</GMapMap>
31+
</template>
32+
33+
<script>
34+
export default {
35+
mounted() {
36+
this.$refs.myMapRef.$mapPromise.then((mapObject) => {
37+
console.log('map is loaded now', mapObject);
38+
});
39+
},
40+
data() {
41+
return {
42+
center: { lat: 51.093048, lng: 6.84212 },
43+
markers: [
44+
{
45+
position: {
46+
lat: 51.093048,
47+
lng: 6.84212,
48+
},
49+
},
50+
{
51+
position: {
52+
lat: 51.198429,
53+
lng: 6.69529,
54+
},
55+
},
56+
{
57+
position: {
58+
lat: 51.165218,
59+
lng: 7.067116,
60+
},
61+
},
62+
{
63+
position: {
64+
lat: 51.09256,
65+
lng: 6.84074,
66+
},
67+
},
68+
],
69+
};
70+
},
71+
};
72+
</script>
73+
74+
<style>
75+
body {
76+
margin: 0;
77+
}
78+
</style>
79+
80+
81+
```

0 commit comments

Comments
 (0)