1

I am working on a webpage that is supposed to be displaying a google map. However, I can not get it to display properly. I have a good API key as I can get the JSON file. Any advice would be appreciated.

index.html:

<script src="https://maps.googleapis.com/maps/api/js?key=***APIKEY***&callback=initMap"></script>

*note I have seen it done with and without the callback.

LocationMap.vue:

<template>
    <v-app>
        <div id='ConnectMap'>
            <div ref='map'>
            </div>
        </div>
    </v-app>
</template>
<script>
export default {
    name: 'Map',
    data() {
        return{
            map:null,
            mapCenter:{lat:37.773972,lng:-122.431297}
        }
    },
mounted(){
this.initMap();
},
    methods:{

            // initMap()
        
        initMap(){
            this.map = new google.maps.Map(this.$refs.map,{
                center: this.mapCenter,
                zoom: true,
                maxZoom: 20,
                minZoom: 3,
                streetViewControl: true,
                mapTypeControl: true,
                fullscreenControl: true,
                zoomControl: true
            })
        
    }
    }
}
</script>

currently, as the code is I get an uncaught in promise error. The error states that initMap is not a function. If I remove the callback I get no error message. Either way, my map does not display.

UPDATE I added a call to initMap inside mounted. However, this is now giving me a race condition on setzoom.

5
  • Where are you calling initMap? Commented Apr 27, 2021 at 13:53
  • I was actually missing the call for initMap. I updated my question, with the call and a new race condition error. Commented Apr 27, 2021 at 14:12
  • Thanks for updating, can you please add more information about the race condition error you're seeing? Commented Apr 27, 2021 at 17:20
  • What do you mean by "a race condition on setzoom"? Commented Apr 27, 2021 at 23:05
  • There are different ways to integrate Google Maps in vue. You can check this: stackoverflow.com/questions/44634193/… Commented Jul 13, 2021 at 0:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.