我一直在尝试根据固定区域下载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 ) );
}
}
如果我遗漏了任何其他细节,请告诉我,以便更清楚地展示此错误,谢谢!
答案 0 :(得分:1)