我一直在尝试下载OSM Tiles以供基于固定区域的离线使用,并且代码已经运行良好一段时间了。
但是,我最近遇到了这个错误:
ERROR(8936): recvfrom failed: ECONNRESET (Connection reset by peer)
我只是想知道这是否是由于 OSM 的服务器问题造成的,或者是某种低效的编码约定导致了此问题?
这些是我的下载代码:
for (int y = placeTopLeft.getYTile(); y <= placeBottomLeft.getYTile(); y++){
for(int x = placeTopLeft.getXTile(); x <= placeBottomRight.getXTile(); x++){
try {
String urlStr = "http://a.tile.openstreetmap.org/"+ v +"/"+x+"/"+y+".png";
URL url = new URL(urlStr);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
File newFileDir = new File(Environment.getExternalStorageDirectory().toString()
+ "/test/"+ tID+ "/"+v+"/"+x);
newFileDir.mkdirs();
File newFile = new File(newFileDir, y+".png");
OutputStream output = new FileOutputStream(newFile);
int read;
while ((read = in.read()) != -1) {
output.write(read);
output.flush();
}
urlConnection.disconnect();
} catch (Exception e) {
mNotificationHelper.cancelled();
Log.e("URL::: ERROR", e.getMessage());
e.printStackTrace();
}
loopCount++;
publishProgress( (int) ((loopCount/totalLoopCount) * 100 ) );
}
}
如果我缺少任何其他详细信息,请告诉我,以便更清楚地展示此错误,谢谢!
最佳答案
你看过你之前得到的瓷砖吗?它们是真正的 Mapnik 瓷砖吗?当我使用 a.tile.openstreetmap.org、b.tile.openstreetmap.org 或 c.tile.openstreetmap.org 时,很快图 block 就只显示开放街道 map Logo 和消息“此应用程序因过度使用而被阻止......” ..我们的服务器”。
关于java - 下载 OSM Tiles,连接被对等方重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14171683/