I am trying to add a function inside another function for the Google Maps API marker option. I am having problems with trying to add the function as an argument for the addMarker({coordinates:{lat: 51.506, lng: -0.188}}); method.
I am trying to pass an argument into the function to be able to add it as a variable but it didn't work and I had to comment it.
function initMap() {
map = new google.maps.Map(document.getElementById("map"), options);
function addMarker(props) {
let marker = new google.maps.Marker ({
position:props.coordinates,
map : map,
icon: "img/logo2.png",
});
//contentInfo = function addInfoWindow(contentWindow) {
let infoWindow = new google.maps.InfoWindow({
content: "<h3>Tower</h3>"
});
marker.addListener("click", function(){
infoWindow.open(map, marker);
});
//}
}
//Add Marker
addMarker({coordinates:{lat: 51.506, lng: -0.188}});
addMarker({coordinates:{lat: 51.497, lng: -0.129}});
addMarker({coordinates:{lat: 51.515, lng: -0.098}});
}
Edit
I actually want to be able to call this function:
contentInfo = function addInfoWindow(contentWindow) {
let infoWindow = new google.maps.InfoWindow({
content: "<h3>Tower</h3>"
});
marker.addListener("click", function(){
infoWindow.open(map, marker);
});
}
From within the function addMarker. Something like this:
function addMarker({coordinates:{lat: 51.515, lng: -0.098}, infoWindow()});
But I can't find the proper logic or syntax to accomplish that.