Determine if coordinate is inside region (MKMapView, solve in PHP) -
i'm using mkmapview
, send php program visible region (center lat, center lon, span lat, span lon). need determine if coordinate inside region using php. i'm hoping there's standard formula somewhere, haven't found one. i'll keep trying come formula, it's surprisingly complicated (hopefully not as haversine, don't believe have figured out myself).
lets try logic
$toprightlongitude = $centerlongitude + $spanlongitude/2; if($toprightlongitude > 180 , ($pointlongitude < 0)) $toprightlongitude = $toprightlongitude - 360; // (180*2) - positive becomes negative $bottomleftlongitude = $centerlongitude - $spanlongitude/2; if($bottomleftlongitude< -180 , ($pointlongitude > 0)) $bottomleftlongitude= 360 + $bottomleftlongitude; // negative , become positive $toprightlatitude = $centerlatitude + $spanlatitude/2; if($toprightlatitude > 90 , ($pointlatitude < 0)) $toprightlatitude = $toprightlatitude - 180; // (90*2) - positive becomes negative $bottomleftlatitude = $centerlatitude - $spanlatitude/2; if($bottomleftlatitude< -90 , ($pointlatitude > 0)) $bottomleftlatitude= 180 + $bottomleftlongitude; // negative , become positive
if have
$centerlongitude = 179; $spanlongitude = 20; $pointlongitude = -179;
results
$toprightlongitude = -171; $bottomleftlongitude = 169;
so point in if test this:
if($pointlongitude < $toprightlongitude && $pointlongitude > $bottomleftlongitude && $pointlatitude < $toprightlatitude && $pointlatitude > $bottomleftlatitude){ echo 'in'; }else{ echo 'out'; }
Comments
Post a Comment