I have a page to display Google Map output with a set (40+) custom markers set on the page, (this is a redevelopment of an existing system (but poorly coded).
My issue is that the map does not output, there is no content inside the <div id='map'>
. There are no errors on browser consoles so am at a bit of a loss as to how to approach this issue.
I have commented out various parts of my code (such as marker placement) but this also does not seem to fix it.
Page code:
<!DOCTYPE html>
<head>
<script type="text/javascript">
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
/* mapTypeId: google.maps.MapTypeId.ROADMAP,*/
center: {lat: 52.345617, lng: 1.502666}
});
/** setMarkers(map);**/
/***
infowindow = new google.maps.InfoWindow({
content: "holding..."
});**/
}
/*** map still loads blank even when commenting all the below JS **/
/***
var places = [
// Name | lat | long | order | infoWindowDescr
['Dud Data', 52.3283777, 1.6753005, 12, 'some descriptive text']
<?php
//this PHP is a working Javascript array of marker data
// disabled for testing but seems ok.
//print $placesOutput;
?>
];
function setMarkers(map) {
// Adds markers to the map.
for (var i = 0; i < places.length; i++) {
var business = places[i];
var marker = new google.maps.Marker({
title: business[0],
position: {lat: business[1], lng: business[2]},
map: map,
zIndex: business[3]
});
google.maps.event.addListener(places, 'click', function (){
infowindow.setContent(business[4]);
infowindow.open(map, this);
})
}
}
**/
</script>
<script type="text/javascript" defer async
src="https://maps.googleapis.com/maps/api/js?key=APIKey&callback=initMap">
</script>
</head>
<body>
<div id='map' style='height:500px;width:500px;'></div>
</body>
</html>
What I've tried so far:
The source code is from the Google developer docs here and various related Google pages.
Code for the multiple markers info window
was from another site.
I have read this question, this question and this question - the third question caused me to reorder my code so that the reference to the API came after the functions were established.
I have NO ERRORS in consoles on browsers (Firefox/Chrome); I don't seem to have any javascript errors.
I am currently testing without PHP data so Question 2 would not apply here.
My API key is correctly working.
I have tried reordering the Javascript code as well as placing the code before/after the DIV element, but no change.
Disabling the places array, setMarker function, and infoWindow function also does not make it work.
There is no other javascript running on the page.
I'm sure it's something simple but I can't see it....