Dépliant:: Comment vérifier le point se trouve à l'intérieur/à l'extérieur du polygone ou du rectangle [fermé]

s'il n'existe aucun algorithme pour vérifier marqueur se trouve à l'intérieur ou à l'extérieur du Polygone, Rectangle et le cercle. J'ai essayé d'écrire une fonction à l'aide de ce lien. mais pas de succès.

19
demandé sur Thesane 2013-06-03 09:04:55

3 réponses

il y a une fonction dans la notice pour vérifier cela.

Polygon.getBounds().contains(MarketLatLng);
17
répondu Thesane 2013-08-15 18:17:56

si vous utilisez PHP alors cette fonction fonctionne

$c = false; 

$vertices_x = array(22.333,22.222,22,444);  //latitude points of polygon
$vertices_y = array(75.111,75.2222,76.233);   //longitude points of polygon
$points_polygon = count($vertices_x); 
$longitude =  23.345; //latitude of point to be checked
$latitude =  75.123; //longitude of point to be checked

if (is_in_polygon($points_polygon, $vertices_x, $vertices_y, $longitude, $latitude)){
    echo "Is in polygon!"."<br>";
}
else { 
    echo "Is not in polygon"; 
}

function is_in_polygon($points_polygon, $vertices_x, $vertices_y, $longitude_x, $latitude_y) {
    $i = $j = $c = 0;

    for ($i = 0, $j = $points_polygon-1; $i < $points_polygon; $j = $i++) {
        if (($vertices_y[$i] >  $latitude_y != ($vertices_y[$j] > $latitude_y)) && ($longitude_x < ($vertices_x[$j] - $vertices_x[$i]) * ($latitude_y - $vertices_y[$i]) / ($vertices_y[$j] - $vertices_y[$i]) + $vertices_x[$i])) {
            $c = !$c;
        }
    }

    return $c;
}
5
répondu Vincentos 2014-06-27 12:36:37
<!-- <!DOCTYPE html>
<html>
  <head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
       #map-canvas {
        margin: 0;
        padding: 0;
        width: 700px;
        height: 500px;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
var map;
var marker;
var latlong = [["21.001663","75.486069"],
["20.108977","73.914672"],
["21.1458","79.088155"],
["19.153061","77.305847"],
["20.0831","73.79095"],
["18.52043","73.856744"],
["16.774832","74.486265"],
["16.691308","74.244866"],
["19.876165","75.343314"],
["19.997453","73.789802"],
["20.532949","76.184303"],
["21.013321","75.563972"],
["18.9513","72.82831"],
["18.515752","73.182162"],
["19.075984","72.877656"],
["19.218331","72.97809"],
["19.844006","79.36266"],
["20.745319","78.602195"],
["21.267052","78.577973"],
["18.52043","73.856744"],
["19.96955","79.304654"],
["19.450585","72.799155"],
["18.52043","73.856744"],
["20.745319","78.602195"],
["18.9833","75.7667"],
["21.013321","75.563972"],
["21.1458","79.088155"],
["19.153061","77.305847"]];

function initialize() {
  var mapOptions = {
    zoom: 4,
    center: new google.maps.LatLng(21.7679, 78.8718),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
      drawCircle();
}
function drawCircle() 
{
var options = {
        strokeColor: '#800000',
        strokeOpacity: 1.0,
        strokeWeight: 1,
        fillColor: '#C64D45',
        fillOpacity: 0.5,
        map: map,
        center: new google.maps.LatLng(21.7679, 78.8718),
        radius: 100000
    };

    circle = new google.maps.Circle(options);
    var bounds= circle.getBounds(); 
    for (var i = 0; i < latlong.length; i++){
    var hello =new google.maps.LatLng(latlong[i][0], latlong[i][1]);
    if(bounds.contains(hello)) 
    {
       marker= new google.maps.Marker({
      position:hello,
       });
       marker.setMap(map);
          console.log("Hi iam in bound");

          }
          else
          {
             console.log("Iam not in bound");
}
}

}
google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html> -->
0
répondu Saurabh Yadav 2013-08-19 11:52:35