2
I need to know through coordinates if I’m in a region area, in this case, the code below is in PHP with polygon, but it’s not working. Am I missing the question of co-ordination (x, y)?
I searched something with the Google Maps API, but so far nothing.
<?php
$vertices_x = array(-4.0680,-4.0352,-4.1180,-4.0708,); // x-coordinates of the vertices of the polygon
$vertices_y = array( -63.1391,-63.0330,-63.1065, -63.0087); // y-coordinates of the vertices of the polygon
$points_polygon = count($vertices_x); // number vertices
//$longitude_x = $_GET["longitude"]; // x-coordinate of the point to test
//$latitude_y = $_GET["latitude"]; // y-coordinate of the point to test
//// For testing. This point lies inside the test polygon.
$longitude_x = 4.0756;
$latitude_y = -63.0753;
if (is_in_polygon($points_polygon, $vertices_x, $vertices_y, $longitude_x, $latitude_y)){
echo "estou na area";
}
else echo "nao estou na area";
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;
}
?>
Something very similar http://www.princiweb.com.br/blog/programacao/google-apis/google-maps-polygon.html but it also didn’t work
– Grupo Leopardo
https://developers.google.com/maps/documentation/geocoding/start#ReverseGeocoding
– user60252
I tried to open but it showed nothing
– Hemerson Prestes
I figured I’d put it in my code
– Hemerson Prestes
It worked now only this giving an error here $c = ! $c;
– Hemerson Prestes
Where has
// $i = $j = $c = 0;
puts$c = 0;
– Sam
Perfect Thank you very much !
– Hemerson Prestes
https://stackoverflow.com/questions/14750275/haversine-formula-with-php
– epx