I’m been running into this JS error, from google map that is loading on my contact page, and I’m not sure how to fix this.
I’ve also uploaded my js and contact page for further reference.
The error (console error in Chrome // IE 8 and up // but not firefox for some reason):
Uncaught TypeError: Cannot read property 'offsetWidth' of null
Xi main.js:40
Jj main.js:46
(anonymous function) g-maps.js:33
The html:
<div id="find-us">
<div class="contact-fs">
<span class="icon-map"></span>
</div>
<h3>Find Us</h3>
<div id="map"></div>
<div class="clearfix"></div>
</div>
Google map js:
// Define your locations: HTML content for the info window, latitude, longitude
var locations = [
['<div class=\"g-map-loc\"><h5>Consolidated Gypsum Supply Ltd.</h5><p> Edmonton West</p><p>11660 170th Street NW Edmonton Alberta T5S 1J7 </p></div>', 53.566711, -113.615498],
['<div class=\"g-map-loc\"><h5>Consolidated Gypsum Supply Ltd.</h5><p>Edmonton East</p><p>5510 125A Ave NW Edmonton, AB T5W 1V3 </p></div>', 53.583191, -113.426527],
['<div class=\"g-map-loc\"><h5>Consolidated Gypsum Supply Ltd.</h5><p>Edmonton South</p><p>1215 95 St SW Edmonton, AB T6X 0P8 </p></div>', 53.419232, -113.481741],
['<div class=\"g-map-loc\"><h5>Consolidated Gypsum Supply Ltd.</h5><p>Calgary North</p><p>Bay 6, 2835 - 19th Street NE Calgary, Alberta T2E 7A2 </p></div>', 51.076998, -114.011838],
['<div class=\"g-map-loc\"><h5>Consolidated Gypsum Supply Ltd.</h5><p>Calgary South</p><p>4140 - 120th Avenue SE Calgary, Alberta T2Z 4H4 </p></div>', 50.943326, -113.974716],
['<div class=\"g-map-loc\"><h5>Consolidated Gypsum Supply Ltd.</h5><p>Red Deer</p><p>7891 - 49th Avenue Red Deer, Alberta T4P 2B4 </p></div>', 52.310847, -113.809881],
['<div class=\"g-map-loc\"><h5>Consolidated Gypsum Supply Ltd.</h5><p>Saskatoon</p><p>3630 Thatcher Avenue Saskatoon, Saskatchewan S7R 0H6</p></div>', 52.191146, -106.677581]
];
// Setup the different icons and shadows
var iconURLPrefix = 'http://maps.google.com/mapfiles/ms/micons/';
var icons = [
iconURLPrefix + 'orange-dot.png',
iconURLPrefix + 'green-dot.png',
iconURLPrefix + 'blue-dot.png',
iconURLPrefix + 'red-dot.png',
iconURLPrefix + 'purple-dot.png',
iconURLPrefix + 'pink-dot.png',
iconURLPrefix + 'yellow-dot.png'
]
var icons_length = icons.length;
var shadow = {
anchor: new google.maps.Point(15,33),
url: iconURLPrefix + 'msmarker.shadow.png'
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(52.126909, -110.009317),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM
}
});
var infowindow = new google.maps.InfoWindow({
maxWidth: 250
});
var marker;
var markers = new Array();
var iconCounter = 0;
// Add the markers and infowindows to the map
for (var i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon : icons[iconCounter],
shadow: shadow
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
iconCounter++;
// We only have a limited number of possible icon colors, so we may have to restart the counter
if(iconCounter >= icons_length){
iconCounter = 0;
}
}
function AutoCenter() {
// Create a new viewpoint bound
var bounds = new google.maps.LatLngBounds();
// Go through each...
$.each(markers, function (index, marker) {
bounds.extend(marker.position);
});
// Fit these bounds to the map
map.fitBounds(bounds);
}
AutoCenter();
Footer scripts:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.0.js"></\script>')</script>
<!--Javascript google maps -->
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="assets/js/g-maps.js"></script>
Here is the website:
enter link description here
Uploaded files:
g-maps.js (3.6 KB)
contact.php (17.9 KB)