Google 地图上的多个标记和信息窗口(使用 MySQL) [英] Multiple markers and infowindows on Google Maps (using MySQL)
本文介绍了Google 地图上的多个标记和信息窗口(使用 MySQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
另外四个 if 语句对其他类别执行相同的操作.
There are another four if statements which do the same thing for other categories.
<?php
if (isset($_POST['one'])) {
$query = "SELECT * FROM beerstable WHERE category LIKE "%Lager%"";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_assoc($result)) {
$lat = $row['lat'];
$lng = $row['lng'];
$markername = $row['name'];
$link = $row['link'];
$photo = $row['photo'];
?>
var infowindow = new google.maps.InfoWindow({
content: '<h1><?php echo $markername ?></h1><br><img src="<?php echo $photo ?>" height="30" width="50"><br><a href="<?php echo $link ?>"><?php echo $link ?></a>'
});
icon = "yellow";
icon = "http://maps.google.com/mapfiles/ms/icons/" + icon + ".png";
var marker = new google.maps.Marker({
title: '<?php echo $markername ?>',
animation: google.maps.Animation.DROP,
//animation: google.maps.Animation.BOUNCE,
icon: new google.maps.MarkerImage(icon),
position: new google.maps.LatLng( <? php echo $lat ?> , <? php echo $lng ?> )
});
marker.setMap(map);
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
<?php
}
}
?>
它会显示标记,但是当我单击一个标记时,它会显示最后创建的标记的信息窗口.
It displays the markers, but when I click a marker it displays the infowindow of last marker that created.
推荐答案
hear :
var infowindow = new google.maps.InfoWindow({
content: '<h1><?php echo $markername ?></h1><br><img src="<?php echo $photo ?>" height="30" width="50"><br><a href="<?php echo $link ?>"><?php echo $link ?></a>'
});
创建 1 个数组 infowindow .
Create 1 array inforwindow .
改成
$i ++;
infowindow[<?php echo $i; ?>] = new google.maps.InfoWindow({
content: '<h1><?php echo $markername ?></h1><br><img src="<?php echo $photo ?>" height="30" width="50"><br><a href="<?php echo $link ?>"><?php echo $link ?></a>'
});
和
marker[<?php echo $i; ?>] = new google.maps.Marker({...});
google.maps.event.addListener(marker[$i], 'click', function() {
infowindow[<?php echo $i; ?>].open(map,this);
});
这篇关于Google 地图上的多个标记和信息窗口(使用 MySQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文