我使用MKMapView
,我送我的PHP程序可見光區(LAT中心,中心經度,緯度跨度,跨度LON)。我需要確定一個座標是否在該區域內使用PHP。我希望有一個標準的公式,但我沒有找到一個。我會繼續努力想出一個公式,但它非常複雜(希望不會像束縛者那樣多,我不相信自己能想出來)。確定是否座標內的區域(的MKMapView,解決PHP)
8
A
回答
1
我的解決方案
$top = $c_lat + ($d_lat/2.0);
$bottom = $c_lat - ($d_lat/2.0);
$left = $c_lon - ($d_lon/2.0);
$right = $c_lon + ($d_lon/2.0);
if($left < -180)
{
$second_left = $left + 360.0;
$second_right = 180.0;
$left = -180;
}
elseif($right > 180)
{
$second_right = $right - 360.0;
$second_left = -180.0;
$right = 180.0;
}
$inside = false;
if($t_lat > $bottom && $t_lat < $top && $t_lon > $left && $t_lon < $right)
$inside = true;
else if($second_right && $second_left)
{
if($t_lat > $bottom && $t_lat < $top && $t_lon > $second_left && $t_lon < $second_right)
$inside = true;
}
if($inside)
{
}
這似乎與MKMapView
工作,因爲該地區的緯度總是-90和90
0
這個邏輯應該工作:
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 ...";
}
+0
之間我希望它是這麼簡單。我應該澄清一下,'mapView.region'的緯度座標是-90到90,經度-180到180.這是一個棘手的部分。如果點經度爲-179,而區域中心的長度爲179,並且跨度爲20,則上述第三個條件將是錯誤的,但該點仍然可以位於內部。 –
3
讓我們嘗試這個邏輯
$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';
}
0
我以前工作過我自己的問題的解決方案,但對於十進制值和它的作品。可能是如果你可以將deg轉換爲十進制,它可能會工作。
我已經按照你的問題改名爲變量。
這裏的邏輯。
if
(
(
($lat - $spanLat) < $centerLat &&
$centerLat < ($lat+ $spanLat)
) &&
(
($long - $spanLong) < $centerLong &&
$centerLong < ($long + $spanLong)
)
)
相關問題
- 1. 檢查座標是否在區域內
- 2. 檢查座標是否在預定義的區域內
- 3. iOS - 確定座標是否在GMSPolyline內
- 4. 如何檢測GPS座標是否落在MKMapView的某個區域?
- 5. 查找座標是否在區域
- 6. 如何確定座標是否在當前可見的地圖區域中?
- 7. MKMapView檢測是否有點座標POI
- 8. 使用哪種算法來確定座標是否位於特定區域?
- 9. 獲取某個區域內的座標
- 10. 檢測觸摸座標是否位於自定義視圖上可觸摸區域的座標內
- 11. 獲取區域內的座標座標 - Google地圖
- 12. 添加註解爲座標的MKMapView
- 13. 如何確定哪些地理座標位於已定義的區域內?
- 14. 的MKMapView秀正確保存區域
- 15. PDFBox的PDFTextStripperByArea區域座標
- 16. 確定一個座標是否在另一個的半徑內
- 17. MKMapview座標UTM32
- 18. 確定點是否位於有界區域內的算法
- 19. Android:確定縮放時可視區域的座標
- 20. 如何確定郵政編碼是否在指定區域內?
- 21. 確定點是否位於特定幾何區域內
- 22. 座標在區域標記
- 23. 確定CGPoint是否在圖像區域
- 24. MKMapView最大的區域是什麼?
- 25. 確定座標是否在矢量形狀內
- 26. 如何確定一個座標是否在mutilpolygon內?
- 27. 確定3d座標是否在平截頭體內
- 28. MKMapView設置區域
- 29. 如何確定點是否在按鈕區域內
- 30. 如何從UTM座標確定UTM區域
我看着你的代碼,看起來不對我,我做了一個測試中心(179,89)和跨度(20,20)和點(-179,-89),我得到了外面,但點在裏面,因爲179 + 10 = 189得到-171和89 + 10 = 99得到-81所以這個點在中心和右上角之間。 – Macerier
mapView只能從左到右滾動,所以你的中心緯度不能超過89,跨度不能超過2.我基本上只做了兩個區域,如果區域超過了180或-180,那麼它們都會被測試。另外,你的anwswer是有用的,但是這個例子看起來像是在邏輯之外,當它實際在裏面。 ('$ pointLongitude> $ bottomLeftLongitude') –