【发布时间】:2015-09-05 22:03:50
【问题描述】:
所以我基本上是从数据库中提取 lat 和 lng 并使用这些坐标在地图上绘制一个圆圈。
除了我的 infoWindow 在填充正确的信息时,它在完全相同的圆圈上弹出,而不是我单击的那个圆圈之外,一切都运行良好。
我在这里阅读了几篇文章,但似乎无法找到我做错了什么。
<script type="text/javascript">
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.TERRAIN
});
var markerBounds = new google.maps.LatLngBounds();
var cityLocation;
<?php foreach($allResults as $key =>$singleResult): ?>
cityLocation = new google.maps.LatLng(<?php echo $singleResult["lat"] ?>, <?php echo $singleResult["lng"] ?>);
// Draw a marker for each random point
var circle = new google.maps.Circle({
center: cityLocation,
radius: <?php echo $meters ?>,
position: cityLocation,
strokeColor: "#222",
strokeOpacity: 0.1,
strokeWeight: 2,
fillColor: "#ff0007",
fillOpacity: 0.2,
clickable:true,
map: map
});
circle.info = new google.maps.InfoWindow ({
content:'<?php echo "Lat: " . $singleResult["lat"] . " " . "Lng: " . $singleResult["lng"] ?> '
});
google.maps.event.addListener(circle,'click',function() {
this.info.open(map, circle);
});
// Extend markerBounds with each random point.
markerBounds.extend(cityLocation);
<?php endforeach; ?>
// Map.fitBounds() method to set the map to fit markerBounds
map.fitBounds(markerBounds);
【问题讨论】:
标签: javascript php mysql google-maps