I have coded the javascript for my google maps as shown below. The code works perfectly fine but if I happen to add any other javascript code relating to something different it ceases to work and produces errors. I need assistance to debug what the problem is
// Initialize and add the map
window.initMap = initMap;
// Initialize and add the map
var map;
var InforObj = [];
var centerCords = {
lat: 37.78345,
lng: -122.45792
};
var markersOnMap = [{
placeName: "Vigor XF in Financial District",
address: "QHVX+JW Financial District, San Francisco,<br> CA, USA",
LatLng: [{
lat: 37.79412182661146,
lng: -122.40019568708203
}]
},
{
placeName: "Vigor XF in Lower Haight",
address: "QHCC+GG Lower Haight, San Francisco,<br> CA, USA",
LatLng: [{
lat: 37.771363364156834,
lng: -122.42870896060947
}]
},
{
placeName: "Vigor XF in Outer Richmond",
address: "40406 Balboa St., San Francisco,<br> CA, 94121 USA",
LatLng: [{
lat: 37.775897080821615,
lng: -122.49445723177357
}]
}
];
window.onload = function () {
initMap();
};
function addMarkerInfo() {
for (var i = 0; i < markersOnMap.length; i++) {
var contentString = '<div id="content"><b><h6>' + markersOnMap[i].placeName +
'</h6><p>'+ markersOnMap[i].address +'</p><p> <table > <tr><th style="font-weight: normal;">MON - THU</th><td style="padding-left:10px;">05:30-20:00</td></tr> <tr><th style="font-weight: normal;">FRI</th><td style="padding-left:10px;">05:30-18:00</td></tr> <tr><th style="font-weight: normal;">SAT</th><td style="padding-left:10px;">07:00-14:30</td></tr> <tr><th style="font-weight: normal;">SUN</th><td style="padding-left:10px;">10:00-13:00</td></tr> </table> </p> <img style="margin-right:10px" height="75px" width="75px" src="img/1@2x (2).png"><img style="margin-right:10px" height="75px" width="75px" src="img/2 (2).png"><img style="margin-right:10px" height="75px" width="75px" src="img/3 (2).png"><img style="margin-right:10px" height="75px" width="75px" src="img/4 (2).png"></div>';
const image =
"img/Pin.png";
const beachMarker = new google.maps.Marker({
position: markersOnMap[i].LatLng[0],
map,
icon: image,
});
const infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 400
});
beachMarker.addListener('click', function () {
closeOtherInfo();
beachMarker.setIcon("img/Selected.png");
infowindow.open(beachMarker.get('map'), beachMarker);
InforObj[0] = infowindow;
});
beachMarker.addListener('mouseover', function () {
beachMarker.setIcon("img/Selected.png");
});
beachMarker.addListener('mouseout', function () {
beachMarker.setIcon("img/Pin.png");
});
}
}
function closeOtherInfo() {
if (InforObj.length > 0) {
/* detach the info-window from the marker ... undocumented in the API docs */
InforObj[0].set("marker", null);
/* and close it */
InforObj[0].close();
/* blank the array */
InforObj.length = 0;
}
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 13.75,
scrollwheel: false,
draggable: false,
panControl: true,
zoomControl: true,
mapTypeControl: true,
scaleControl: true,
streetViewControl: true,
overviewMapControl: true,
rotateControl: true,
center: centerCords
});
addMarkerInfo();
}
Or anyone who can hel me to write code to produce such a map as shown below.
Google map