I am attempting to add infowindows to the markers with PlaceDetails that are returned after a google searchbox search. When I click on the markers no infowindows open. I cannot
To get the Place Details to use in the InfoWindow, you need to make a second request to the Places API (when the marker is clicked). Inside the createMarker function (which has function closure on the "place"):
var request = {
reference: place.reference
};
google.maps.event.addListener(marker,'click',function(){
service.getDetails(request, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
var contentStr = ''+place.name+'
'+place.formatted_address;
if (!!place.formatted_phone_number) contentStr += '
'+place.formatted_phone_number;
if (!!place.website) contentStr += '
'+place.website+'';
contentStr += '
'+place.types+'
';
infowindow.setContent(contentStr);
infowindow.open(map,marker);
} else {
var contentStr = "No Result, status="+status+"
";
infowindow.setContent(contentStr);
infowindow.open(map,marker);
}
});
});
Example