I can’t seem to get this combo to work. I’ve tried both the vue2-google-maps
and Akryum’s Vue-googlemaps
NPMs and neither work. I’ve copied code from the documentation and from the provided samples with no luck. In the former case, I get ReferenceError: MarkerClusterer is not defined (even though I installed marker-clusterer-plus
), in the latter case, I get no errors or warnings and no map rendered. In both cases lodash
, marker-clusterer-plus
, vue
, and vueBootstrap
are imported globally.
I’m trying to render the map inside a div which is nested in a Bootstrap container. Here is the code for the vue2-google-maps version:
<template>
<div class="map-container">
<p>Google map goes here</p>
<gmap-map
:center="{lat:1.38, lng:103.8}"
:zoom="12"
map-type-id="terrain">
</gmap-map>
</div>
</template>
<script>
import MarkerClusterer from 'marker-clusterer-plus';
var VueGoogleMaps = require('vue2-google-maps/dist/vue-google-maps')
Vue.use(VueGoogleMaps, {
load: {
apiKey: 'AIzaSyCzcadxaoXuPGaqQ_u4OCW-kY4IhIQ5R_Q',
},
});
export default {
name: "maps",
data () {
return {
center: {
lat: 48.853,
lng: 2.298,
},
userPosition: null,
zoom: 12,
}
},
}
</script>
<style>
.map-container {
width: 500px;
height: 300px;
}
</style>
Akryum’s VueGoogleMaps version:
<template>
<div>
<p>Google map goes here</p>
<googlemaps-map
class="map"
ref="map"
:center.sync="center"
:zoom.sync="zoom"
>
<googlemaps-user-position
@update:position="setUserPosition"
/>
<!-- Marker -->
<googlemaps-marker
title="Paris"
:position="{ lat: 48.8735, lng: 2.2951 }"
/>
</googlemaps-map>
</div>
</template>
<script>
import 'vue-googlemaps/dist/vue-googlemaps.css';
import VueGoogleMaps from 'vue-googlemaps';
Vue.use(VueGoogleMaps, {
load: {
apiKey: ' AIzaSyCzcadxaoXuPGaqQ_u4OCW-kY4IhIQ5R_Q ',
libraries: ['places'],
},
});
export default {
name: "maps",
data () {
return {
center: {
lat: 48.853,
lng: 2.298,
},
userPosition: null,
zoom: 12,
}
},
methods: {
centerOnUser () {
if (this.userPosition) {
this.center = this.userPosition
}
},
setUserPosition (position) {
this.userPosition = position
},
},
}
</script>
In both cases Google map goes here is rendered in the correct spot, but no map is visible. I’m guessing that I need to do something to trigger the render, but can’t find anything in either README or any of the examples. At this point I’m just trying to get a map (any map) to render so things like map size or type or location don’t matter to me right now.
Any help or suggestion would be greatly appreciated. TIA.