我正在尝试检测圆圈中的标记位置。标记从数据库中获取的纬度和经度。我设法检测到标记位置。但是仅来自最后一个标记的警报。如何为每个标记/圆圈显示警报?
截图:screenshoot
查找更多详细信息,请参阅此处:link
尝试将标记拖动到每个圆圈。
提前致谢,抱歉我的英语不好:)
代码:
<script type="text/javascript">
function init_terminal() {
var mapOptions = { center: new google.maps.LatLng(-6.832858,107.953184), zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var dragable_marker = new google.maps.Marker({
position : new google.maps.LatLng(-6.832858,107.953184),
map : map,
draggable : true
});
<?php
$link=koneksi_db();
$sql="select f.*,j.*,ka.*,ke.*,i.*, a.meter from fasum f, jenis_fasum j, kategori_fasum ka, kecamatan ke, instansi i, aturan_jarak a WHERE f.id_jenis=j.id_jenis AND j.id_kategori=ka.id_kategori AND f.id_instansi=i.id_instansi AND f.id_kecamatan=ke.id_kecamatan AND j.id_jenis=a.id_jenis AND f.id_jenis=7";
$res=mysql_query($sql,$link);
$i=0;
while($data=mysql_fetch_array($res)){
$i++;
?>
var image = '../icon/<?php echo $data['icon'];?>';
var marker = new google.maps.Marker({
position: new google.maps.LatLng(<?php echo $data['lat'];?>, <?php echo $data['lng'];?>),
map: map,
icon: image
});
var circle = new google.maps.Circle({
center : new google.maps.LatLng(<?php echo $data['lat'];?>,<?php echo $data['lng'];?>),
radius : <?php echo $data['meter'];?>,
fillColor: "#00ff00",
fillOpacity : .3,
strokeOpacity : .4,
map : map
});
google.maps.event.addListener( dragable_marker, 'dragend', function( e ) {
if (circle.getBounds(this.center).contains(dragable_marker.getPosition() ) ){
document.getElementById("latbox").value = null;
document.getElementById("lngbox").value = null;
alert("Inside!");
}
else {
document.getElementById("latbox").value = this.getPosition().lat();
document.getElementById("lngbox").value = this.getPosition().lng();
}
});
<?php }?>
var kmlOptions = {preserveViewport: 1};
<?php
$res2=mysql_query("SELECT * FROM poligon");
while($poli=mysql_fetch_array($res2)){
?>
layersemua = new google.maps.KmlLayer('<?php echo $poli['url'];?>', kmlOptions);
layersemua.setMap(map,this);
document.getElementById('lihatsemua').checked = true;
<?php }?>
}
</script>
答案 0 :(得分:0)
要检测两个圆圈,请为它们指定唯一名称(circle1,circle2)或使用函数闭包将侦听器与圆圈相关联。