Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes I am getting this error ,,Error in data(): "ReferenceError: google is not defined" #13

Open
hjujah opened this issue Nov 25, 2017 · 2 comments

Comments

@hjujah
Copy link

hjujah commented Nov 25, 2017

This is happening more or less on every second load.
I guess the problem is occurring because the script is being executed before the google maps api is loaded, but I don't know how to sort this out... Any ideas? See the code bellow...

Thanks!

Here is my code from the main:

// Google Maps
import 'vue-googlemaps/dist/vue-googlemaps.css'
import VueGoogleMaps from 'vue-googlemaps'
Vue.use(VueGoogleMaps, {
   load: {
      apiKey: 'AIzaSyDmDuqAPNfa6XEbRVNuaZGhRS6JzGmAmek',
      libraries: ['places'],
   },
})

And the component:

<template>
<googlemaps-map :center.sync="center"
                :zoom.sync="zoom"
                :options="mapOptions"
                @idle="onIdle"
                @click="onMapClick">
   <googlemaps-marker v-for="marker of markers"
                      :key="marker._id"
                      :icon="marker.icon"
                      :position="marker.position"
                      @click="selectMarker(marker._id)" />
</googlemaps-map>

</template>

<script>
import mapStyles from '@/data/mapStyles'

export default {
    name: 'google-map',
    data: () => ({
        mapOptions: {
            minZoom: 5,
            maxZoom: 20,
            draggable: true,
            zoomControl: true,
            scrollwheel: false,
            mapTypeControl: false,
            zoomControl: true,
            zoomControlOptions: {
                position: google.maps.ControlPosition.RIGHT_TOP
            },
            scaleControl: true,
            streetViewControl: false,
            styles: mapStyles
        },

        zoom: 14,
        center: {
            lat: 50.049598, 
            lng: 14.551283
        },
        markers: [

            {
                position: {
                    lat: 50.049598, 
                    lng: 14.551283
                },
                label: {
                    color: 'black',
                    fontFamily: 'Material Icons',
                    fontSize: '20px',
                    text: 'face',
                    // text: 'Conrad and Shark'
                },
                icon: {
                    url : "/static/logo.png",
                    scaledSize: new google.maps.Size(150, 35)
                }
            }
        ]
    }),

    methods: {
        onIdle()  {},
        onMapClick()  {},
        selectMarker(id)  {
            console.log('marker id', id)
        }
    }
}

</script>

<style scoped="">
.vue-google-map {
   position: absolute;
   height: 100%;
   width: 100%;
   left: 0;
   top: 0;
}
</style>
@redxtech
Copy link

redxtech commented Jan 8, 2018

If you ever get a fix for this that would be greatly appreciated.

@maxschulmeister
Copy link

is there a fix for this? $_mapPromises seems to be empty…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants