Google Maps V3 - getting error google is not defined
<p>Lets first start with the google maps code:</p>

<pre><code>var map;

function initialize() {
    var mapOptions = {
        center: new google.maps.LatLng(52.4357808, 4.991315699999973),
        zoom: 2,
        mapTypeId: google.maps.MapTypeId.TERRAIN
    };
    map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}

var seg = {
    1: 'invesCastProd',
    2: 'forged',
    3: 'airframe',
    5: 'corp',
    6: 'structurals'
}

var comp = {
    1: 'structurals',
    2: 'airfoils',
    3: 'airfoils',
    4: 'wyman',
    5: 'energy',
    6: 'strucComp',
    7: 'mechHard',
    8: 'engineProd',
    9: 'corp',
    10: 'aero',
    12: 'timet',
    13: 'specMetals'
}

    var myJSON = {};
    var myMarkers=[];

    $.getJSON("/pcc-common/static/pcc-locations.json", function(json1) {
        myJSON=json1;
        $.each(json1, function(key, data) {
            var latLng = new google.maps.LatLng(data.latitude, data.longitude); 
            // Creating a marker and putting it on the map
            var marker = new google.maps.Marker({
                position: latLng
            });
            myMarkers[key]=marker;
            marker.setMap(map);

            var infoWindow = new google.maps.InfoWindow();

            google.maps.event.addListener(marker, 'click', function() {

                if (infoWindow) {infoWindow.close();}
                infoWindow = new google.maps.InfoWindow({
                    content: "&lt;h5&gt;" + data.display_name + "&lt;/h5&gt;" +
                    "&lt;div&gt;" + data.street+ "&lt;/div&gt;" +
                    "&lt;div&gt;" + data.city + ", " + data.state + " &amp;nbsp; " + data.postal_code + "&lt;/div&gt;" +
                    "&lt;div class='mapPhoneNum'&gt;" + data.telephone + "&lt;/div&gt;" +
                    "&lt;a href=" + data.web_url + "&gt;Website&lt;/a&gt;"
                });
                infoWindow.open(map, marker);
                map.setZoom(15);
                map.panTo(this.getPosition());

                google.maps.event.addListener(infoWindow,'closeclick',function(){
                  resetMapOrigin();
                });

            });

            filterMarkers = function(category){

                var component = category.data("component_id");
                var segment = category.data("segment_id")

                setMapOnAll(null);
                resetMapOrigin();

                var filteredMarkers=[];

                $.each(myJSON, function(key, data) {


                    if( typeof(component)!="undefined" ){

                      if( (myJSON[key].component_id == component) &amp;&amp; (myJSON[key].segment_id == segment) ){ 
                        filteredMarkers.push(key);
                      }

                    }else{
                      if( myJSON[key].segment_id == segment ){
                        filteredMarkers.push(key);
                      }
                    }
                });

                for(i=0;i&lt;filteredMarkers.length;i++){
                    myMarkers[filteredMarkers[i]].setMap(map);
                }
            }

            function setMapOnAll(map) {
                for (var i = 0; i &lt; myMarkers.length; i++) {
                    myMarkers[i].setMap(map);
                }
            }

            function resetMapOrigin(){
              map.setZoom(2);
              map.setCenter({lat:52.4357808,lng:4.991315699999973});
            }
        });

    });
</code></pre>

<p>Here is the initialization script in the html:</p>

<pre><code>&lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAMNhLC5984PO876GF8nesnOqbiKkblvuBo&amp;callback=initialize" async defer&gt;&lt;/script&gt;
</code></pre>

<p>So what is happening is sometimes you open the site and it loads all the pins just fine. You click refresh and it loads all the pins again just fine. Click refresh and it loads again. Click refresh AGAIN and it throws an error <code>Uncaught ReferenceError: google is not defined(...)</code>. And you can refresh multiple times and it will still throw an error. Then all of a sudden on a refresh click it will load all the pins with NO error. So basically sometime it works and other times it gives me an error.</p>

<p>I can't figure out what is happening or why it is doing this.</p>

<p>The line that it is erroring out on is <code>var latLng = new google.maps.LatLng(data.latitude, data.longitude);</code> (obviously cause this is  the first "google" call).</p>

<p>Can anyone tell me why it is doing this?</p>

<p>BTW this is on a development server so it is not live online. But again it works sometimes and sometimes it gives me an error.</p>

<p>Thanks for the help!</p>