【发布时间】:2019-12-04 06:10:09
【问题描述】:
我有一个网站,左侧有一张地图,右侧有对应于地图上每个位置的信息框。如果我单击与标记相对应的 div,该标记的信息窗口会出现在哪里?
PHP:
// the php i use to generate the info boxes i want to click on so the infoWindow pops up for the marker
echo "<div class='highlight' id='" .
$row["bar_name"] .
"'> <h3 class='barTitle bar'>" .
$row["bar_name"] .
"</h3> <h6 class='subTitle'>" .
$row["hourStart"] .
"-" .
$row["hourEnd"] .
" | " .
$row["area"] .
"</h6> <table align='center'> <tr> <th class='dowb'> <button bar_name='" .
$row["bar_name"] .
"' class='weekly'> HH </button></th> <th class='dowb'> <button bar_name='" .
$row["bar_name"] .
"' class='monday'> MON </button></th> <th class='dowb'> <button bar_name='" .
$row["bar_name"] .
"' class='tuesday'> TUE </button></th> <th class='dowb'> <button bar_name='" .
$row["bar_name"] .
"' class='wednesday'> WED </button></th> <th class='dowb'> <button bar_name='" .
$row["bar_name"] .
"' class='thursday'> THU </button></th> <th class='dowb'> <button bar_name='" .
$row["bar_name"] .
"' class='friday'> FRI </button></th> <th class='dowb'> <button bar_name='" .
$row["bar_name"] .
"' class='saturday'> SAT </button></th> <th class='dowb'> <button bar_name='" .
$row["bar_name"] .
"' class='sunday'> SUN </button></th> <br> </tr> </table> <br> <table align='center' class='dowd'> <tr> <th class='barInfoTitle'> Happy Hour Drinks:</th> <th class='barInfoTitle'> Happy Hour Food: </th></tr> <tr> <th class='barInfo' class='dowDrink'>" .
$row["weeklyDealDrinks"] .
"</th> <th class='barInfo' class='dowFood'> " .
$row["weeklyDealFood"] .
" </th> </tr> </table> <div align='center'> <a href='" .
$row["profile_page"] .
"'> More Info </a></div> <hr> </div> \n";
Javascript:
// Creates info window on click/ highlights box (this code is by my other code for adding the google map
var highlight = [];
var infoWindow = new google.maps.InfoWindow(), marker, i;
google.maps.event.addListener(marker, "click", (function (marker, i) {
return function () {
infoWindow.setContent(locations[i][3]);
infoWindow.open(map, marker);
highlight.shift();
highlight.push(locations[i][0]);
for (var j = 0; j < locations.length; j++) {
var check = document.getElementById(locations[j][0]);
if (highlight[0] != locations[j][0]) {
if (check.classList.contains("active")) {
check.classList.remove("active");
}
}
}
}
}
//the js I hvae to try and get the window to pop up (this code is after the previous code)
$(document).ready(function () {
$(".highlight").on('click', function (event) {
event.stopPropagation();
event.stopImmediatePropagation();
alert("works");
infowindow.open(map, Marker);
})
};
【问题讨论】:
-
您能否提供一个minimal reproducible example 来证明您的问题(无需访问您的数据库或 PHP)?
标签: javascript php google-maps google-maps-api-3