gpt4 book ai didi

php - 判断坐标是否在区域内(MKMapView,PHP求解)

转载 作者:可可西里 更新时间:2023-11-01 12:37:32 25 4
gpt4 key购买 nike

我正在使用 MKMapView 并将我的 php 程序发送到可见区域(中心纬度、中心经度、跨度纬度、跨度经度)。我需要使用 php 确定坐标是否在该区域内。我希望某处有一个标准公式,但我还没有找到。我会继续尝试想出一个公式,但它出奇地复杂(希望不像半正弦那么复杂,我不相信我自己能弄清楚)。

最佳答案

让我们试试这个逻辑

$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';
}

关于php - 判断坐标是否在区域内(MKMapView,PHP求解),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30827561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com