假設我有兩點:l1 = (lat1, lng1)
和l2 = (lat2, lng2)
。如何以編程方式生成相距x米的座標網格?獲取兩點之間的座標?
按照這一形象,if I have the two red points and a value x, I want to find out the coordinates of the yellow points
。我知道兩個紅色點之間可能沒有它們之間的距離(水平或垂直),這是x的倍數,這可能導致行和/或列中的最後兩個點的距離小於x。
假設我有兩點:l1 = (lat1, lng1)
和l2 = (lat2, lng2)
。如何以編程方式生成相距x米的座標網格?獲取兩點之間的座標?
按照這一形象,if I have the two red points and a value x, I want to find out the coordinates of the yellow points
。我知道兩個紅色點之間可能沒有它們之間的距離(水平或垂直),這是x的倍數,這可能導致行和/或列中的最後兩個點的距離小於x。
根據您的地圖,您將在地球表面的很小部分上創建一個有界網格網格。這意味着您可以忽略投影數學,只需使用2D代數:減去經度併除以水平網格的數量,然後減去緯度併除以垂直網格的數量。
// source coordinates in decimal degrees
$pOne = [ 'lat' => 35.0, 'lon' => -78.940202 ];
$pTwo = [ 'lat' => 35.010272, 'lon' => -78.721478 ];
// grid size along latitude and longitude
$nLat = 5;
$nLon = 5;
// get the grid size for each dimension in degrees
$dLat = ($pTwo['lat'] - $pOne['lat'])/$nLat;
$dLon = ($pTwo['lon'] - $pOne['lon'])/$nLat;
for ($i = 0; $i < $nLat; $i++) {
$lat = $pOne['lat'] + ($i*$dLat);
for ($j = 0; $j < $nLon; $j++) {
$lon = $pOne['lon'] + ($j*$dLon);
printf('<%.6f, %.6f>' . PHP_EOL, $lat, $lon);
}
}
感謝。太棒了! – iTurki
檢查https://developers.google.com/maps/articles/phpsqlsearch_v3?csw=1和https://www.geodatasource.com/developers/php –