Skip to content
Advertisement

“myMap is not a function” error when using the Google Maps API

I know this has been asked before. But the situation is that I’m referring the function before loading the map api.

This was working a few days ago, and started giving me this error out of nowhere. I’d be grateful if someone could help me.

Error:

enter image description here

    //HTML

    <script src="assets/js/scripts.js"></script>
    <script>

        var markers = [];

        function myMap() {

            var mapProp = {
                center: new google.maps.LatLng(39.7312983, -7.5951745),
                zoom: 5
            };

            var image = 'https://imgur.com/9SsOEZu.png';
            var map = new google.maps.Map(document.getElementById('google-map'), mapProp);
            

            //Some PHP
        }

    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=API_key&callback=myMap">
    </script>
</body>

</html>

Advertisement

Answer

Well, I solved it. The problem had nothing to do with Google Maps API but with a badly inputed value in the database that caused the code to crash before loading any JS.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement