I have this function:
function createMarkersForPlaces(places, infowindow) {
for (var i = 0; i < places.length; i++) {
var place = places[i];
var marker = new google.maps.Marker({
map: map,
title: place.name,
position: place.geometry.location,
id: place.place_id,
animation: google.maps.Animation.DROP
});
placeMarkers.push(marker);
// if user clicks one of the marker, execute getPlaceDetails
// for that specific place
marker.addListener('click', function() {
if (infowindow.marker == this) {
} else {
getPlacesDetails(this, infowindow);
}
});
// based on the places above, populate list in html
$("ul").append("<li><a href='#' onclick='getPlacesDetails(" + marker + "," + infowindow ")' class='w3-bar-item'>" + place.name + "</a></li>");
}
}
but this line of code does not work.
$("ul").append("<li><a href='#' onclick='getPlacesDetails(" + marker + "," + infowindow ")' class='w3-bar-item'>" + place.name + "</a></li>");
inside of a function where marker and infowindow are defined, and other than this line of code, the function works perfect. Marker is an object from google.maps.marker, and infowindow is an object from google.maps.InfoWindow. How can I make it work?
function getPlacesDetails(marker, infowindow) {some function...}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…