Javascript Google Maps API3 多边形多个圆圈
我正在使用 Mysql 和 PHP 生成供 Google 地图使用的 XML。我正在设置标记和多边形圆圈。标记设置没有问题,但是只显示一个多边形圆,而不显示其他九个(从数据库总共返回十个) 我很确定这是一个数组问题,但是我似乎无法解释为什么只创建一个多边形。希望有人能让我指出正确的方向,这是我的代码:
//function to consume xml
var xml = parseXml(data);
var polygonNodes = xml.documentElement.getElementsByTagName("polygon");
for (var i = 0; i < polygonNodes.length; i++) {
var polylatlng = new google.maps.LatLng(
parseFloat(polygonNodes[i].getAttribute("polygon_lat")),
parseFloat(polygonNodes[i].getAttribute("polygon_lng")));
}
createCircle(polylatlng);
//here i am creating the polygon circle
function createCircle(polylatlng) {
var html = "<div id='infodiv'>HelloWorld</div>";
var circle = new google.maps.Circle({
map: map,
center: polylatlng,
fillColor: '#7491D3',
fillOpacity: 0.03,
strokeColor: '#7491D3',
strokeOpacity: 0.1,
strokeWeight: 1,
radius: 18362.55489862987
});
google.maps.event.addListener(circle, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, circle);
});
}
I am using Mysql and PHP to generate XML which is consumed by a Google Map. I am setting markers and polygon circles. The markers set with no problems, however only one polygon circle is displayed, not the other nine (a total of ten is returned from the database)
I am quite certain this is an array issue, however I just cant seem to put my finger on why only one polygon is created. Hopeful someone can get me pointed in the right direction, here is my code:
//function to consume xml
var xml = parseXml(data);
var polygonNodes = xml.documentElement.getElementsByTagName("polygon");
for (var i = 0; i < polygonNodes.length; i++) {
var polylatlng = new google.maps.LatLng(
parseFloat(polygonNodes[i].getAttribute("polygon_lat")),
parseFloat(polygonNodes[i].getAttribute("polygon_lng")));
}
createCircle(polylatlng);
//here i am creating the polygon circle
function createCircle(polylatlng) {
var html = "<div id='infodiv'>HelloWorld</div>";
var circle = new google.maps.Circle({
map: map,
center: polylatlng,
fillColor: '#7491D3',
fillOpacity: 0.03,
strokeColor: '#7491D3',
strokeOpacity: 0.1,
strokeWeight: 1,
radius: 18362.55489862987
});
google.maps.event.addListener(circle, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, circle);
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非我读错了,否则您不会在循环中包含 createCircle 函数,因此它只会被调用一次。尝试:
良好的代码缩进对于解决此类问题很有帮助:)。
Unless I'm reading this wrong, you're not including the
createCircle
function in your loop, so it only gets called once. Try:Good code indentation is helpful for issues like this :).