Google地图上的多个标记和infowindows(使用MySQL) [英] Multiple markers and infowindows on Google Maps (using MySQL)
本文介绍了Google地图上的多个标记和infowindows(使用MySQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?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 =30width =50>< br>< a href =<?php echo $ link?>> ;<?php echo $ link?>< / a>'
});
icon =yellow;
图标=http://maps.google.com/mapfiles/ms/icons/+图标+.png;
var marker = new google.maps.Marker({
title:'<?php echo $ markername?>',
animation:google.maps.Animation。 DROP,
//动画:google.maps.Animation.BOUNCE,
图标:新的google.maps.MarkerImage(图标),
位置:新的google.maps.LatLng(< ;? php echo $ lat?>,< ;? php echo $ lng?>)
});
marker.setMap(map);
google.maps.event.addListener(marker,'click',function(){
infowindow.open(map,marker);
});
<?php
}
}
?>
显示标记,但是当我点击一个标记时,它会显示创建的最后一个标记的infowindow。
解决方案
听到:
> var infowindow = new google.maps.InfoWindow({content:'< h1><?php echo $ markername?>< / h1>< br>< img src =< ?php echo $ photo?>height =30width =50>< br>< a href =<?php echo $ link?>><?php echo $ link?>< / a>'
});
创建1个数组inforwindow。
将其更改为
$ i ++;
infowindow [<?php echo $ i; >] = new google.maps.InfoWindow({
content:'< h1><?php echo $ markername?>< / h1>< br>< img src =<< ;?php echo $ photo?>height =30width =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 );
});
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>'
});
Create 1 array inforwindow .
change it to
$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>'
});
and
marker[<?php echo $i; ?>] = new google.maps.Marker({...});
google.maps.event.addListener(marker[$i], 'click', function() {
infowindow[<?php echo $i; ?>].open(map,this);
});
这篇关于Google地图上的多个标记和infowindows(使用MySQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文