2016-02-01 134 views
2

假设我有两点:l1 = (lat1, lng1)l2 = (lat2, lng2)。如何以编程方式生成相距x米的坐标网格?获取两点之间的坐标?

enter image description here

按照这一形象,if I have the two red points and a value x, I want to find out the coordinates of the yellow points。我知道两个红色点之间可能没有它们之间的距离(水平或垂直),这是x的倍数,这可能导致行和/或列中的最后两个点的距离小于x。

+0

检查https://developers.google.com/maps/articles/phpsqlsearch_v3?csw=1和https://www.geodatasource.com/developers/php –

回答

1

根据您的地图,您将在地球表面的很小部分上创建一个有界网格网格。这意味着您可以忽略投影数学,只需使用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); 
    } 
} 
+0

感谢。太棒了! – iTurki