在googlemap上绘制多个标记,但我对所有标记都得到相同的信息窗口
Plot multiple markers on googlemap, but I'm getting the same infowindow for all markers
我有一个单独的php文件,其中我从mysql数据库检索地址并输出xml文件。然后使用ajax,我试图得到这些地址和地图在谷歌地图。多重infoWindow
是我的问题。我已经挣扎了好几个小时了,请帮帮我。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?signed_in=true"> </script>
<script>
function loadXMLDoc(url)
{
var map;
var mapOptions = {
zoom: 13,
center: {lat:8.719910, lng: 77.740626}
};
map = new google.maps.Map(document.getElementById('map'),
mapOptions);
var xmlhttp;
var txt,x,xx,i,out1,out2,out3,out4;
var markers=[];
var infoWindow = new google.maps.InfoWindow ;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
x=xmlhttp.responseXML.documentElement.getElementsByTagName("details1");
for(i=0;i<x.length;i++)
{
xx=x[i].getElementsByTagName("Latitude");
out1=xx[0].firstChild.nodeValue;
xx=x[i].getElementsByTagName("Longitude");
out2=xx[0].firstChild.nodeValue;
xx=x[0].getElementsByTagName("Nameoforg");
out3=xx[0].firstChild.nodeValue;
xx=x[0].getElementsByTagName("Phoneno");
out4=xx[0].firstChild.nodeValue;
var html = '<p>Donor Location:' +'Nameoforg'+' '+out3+'Phoneno'+out4+' '+ '</p>' ;
markers.push(new google.maps.Marker({
position: { lat:parseFloat(out1), lng: parseFloat(out2)},
map: map
}));
bindinfo(markers[i], map, infoWindow, html);
}
document.getElementById('txtCDInfo').innerHTML=html;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
function bindinfo(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
</script>
</head>
<body onload="loadXMLDoc('mapxml.php')",initialize()>
<div id="txtCDInfo"></div>
<div id="map">
</div>
</body>
</html>
每次都应该像这样初始化infoWindow:
function bindinfo(marker, map, infoWindow, html) {
var infoWindow = new google.maps.InfoWindow({
content: html
});
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 防止Iframe窗体在新窗口中打开
- 内部分区字体大小获胜'调整浏览器窗口大小时不会随媒体查询而更改
- 调整窗口大小时,可拖动的对象会出现在容器外部
- Javascript排序的图像弹出窗口..可以't单独弹出
- 窗口大小html css
- 弹出窗口出现,然后退出
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- Javascript更新孙窗口中的表单元素
- 如何在选项卡上定义属性'的主窗口对象
- CSS-若窗口太小,滚动条会出现在“表格”单元格上
- 召回窗口加载事件 - javascript
- 为什么不显示警报窗口
- 如何使用modalDialog来显示可以在所有浏览器中工作的弹出窗口
- Chrome应用程序调整窗口大小保持纵横比
- 新选项卡被弹出窗口阻止程序阻止
- 如何访问UIWebView'的子窗口上下文
- 刷新父窗口后无法关闭窗口
- 自动关闭弹出窗口的Javascript
- 如何使用特定大小的浏览器窗口打开我的页面