简体   繁体   中英

Detect marker within circle gmap3, only return last marker from database

I am trying to detect the marker position in the circle. Marker Latitude and Longitude taken from the database. I've managed to detect the marker position. But the alerts that come only from the last marker. How do I get alerts appear for each marker/circle?

Screenshot: screenshoot

Look for more details, see here: link

Try drag marker to each circle.

Thanks in advance, and sorry for my bad English :)

code:

    <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>

要检测两个圆圈,请给它们指定唯一的名称(circle1,circle2),或使用函数闭包将侦听器与圆圈相关联。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM