我正在尝试使用OpenStreetMap磁贴在我们的应用中离线使用。我使用给定here的公式从php脚本中提取tile。但是可以清楚地看到,当我放大离线地图时,边界不断减少。我使用以下代码:
$lon1 = -0.147315;
$lon2 = -0.123712;
$lat1 = 51.517074;
$lat2 = 51.505883;
for($zoom = 12; $zoom <= 18; $zoom++){
$xtile1 = floor((($lon1 + 180) / 360) * pow(2, $zoom));
$xtile2 = floor((($lon2 + 180) / 360) * pow(2, $zoom));
$ytile1 = floor((1 - log(tan(deg2rad($lat1)) + 1 / cos(deg2rad($lat1))) / pi()) /2 * pow(2, $zoom));
$ytile2 = floor((1 - log(tan(deg2rad($lat2)) + 1 / cos(deg2rad($lat2))) / pi()) /2 * pow(2, $zoom));
for($xtile = $xtile1; $xtile<=$xtile2+1;$xtile++){
for($ytile = $ytile1;$ytile<=$ytile2+1;$ytile++){
( $xtile + $ytile )% 2 == 0 ? $serverId = 'a' : $serverId = 'b'; //load balancing between 2 servers
$url = "http://" . $serverId . ".tile.openstreetmap.org/" . $zoom . "/" . $xtile . "/" . $ytile .".png";
$img = "central/" . $zoom . "_" . $xtile . "_" . $ytile .".png";
file_put_contents($img, file_get_contents($url));
echo $img . "saved <br>";
sleep(1);
}
}
}
我尝试在初始缩放的范围内放大,但是我得到错误,例如&#34;找不到瓷砖&#34;。有什么我做错了吗?有人可以赐教我吗?
谢谢。