# php - 确定坐标是否在区域内（MKMapView，用PHP解决）

#### 4 个答案:

\$topRightLongitude = \$centerLongitude   \$spanLongitude/2;
if(\$topRightLongitude > 180 and (\$pointLongitude < 0))
\$topRightLongitude = \$topRightLongitude - 360; // (180*2) - positive becomes negative

\$bottomLeftLongitude = \$centerLongitude - \$spanLongitude/2;
if(\$bottomLeftLongitude< -180 and (\$pointLongitude > 0))
\$bottomLeftLongitude= 360   \$bottomLeftLongitude; // now is negative and will become positive

\$topRightLatitude = \$centerLatitude   \$spanLatitude/2;
if(\$topRightLatitude > 90 and (\$pointLatitude < 0))
\$topRightLatitude = \$topRightLatitude - 180; // (90*2) - positive becomes negative

\$bottomLeftLatitude = \$centerLatitude - \$spanLatitude/2;
if(\$bottomLeftLatitude< -90 and (\$pointLatitude > 0))
\$bottomLeftLatitude= 180   \$bottomLeftLongitude; // now is negative and will become positive

\$centerLongitude = 179;
\$spanLongitude = 20;
\$pointLongitude = -179;

\$topRightLongitude = -171;
\$bottomLeftLongitude = 169;

if(\$pointLongitude < \$topRightLongitude &&
\$pointLongitude > \$bottomLeftLongitude &&
\$pointLatitude < \$topRightLatitude &&
\$pointLatitude > \$bottomLeftLatitude){
echo 'in';
}else{
echo 'out';
}

MKMapView

if  ( (\$X > \$center_lat - \$span_lat/2) &&
(\$X < \$center_lat   \$span_lat/2) &&
(\$Y > \$center_lon - \$span_lon/2) &&
(\$Y < \$center_lon   \$span_lon/2) ) {
echo "It's inside!";
} else {
echo "It's outside ...";
}

if
(
(
(\$lat - \$spanLat) < \$centerLat &&
\$centerLat < (\$lat  \$spanLat)
) &&
(
(\$long - \$spanLong) < \$centerLong &&
\$centerLong < (\$long   \$spanLong)
)
)

0条回复