java - 下载 OSM Tiles,连接被对等方重置

标签 java android osmdroid download

我一直在尝试下载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/

相关文章:

android - 无法解析符号 'MyApi'

android - 更改 MapView 方向

android - OSM 中的离线路由 - android

java - 如何使用 JSP EL 动态访问请求参数?

android - 我如何更改 WebView#PostUrl() 的 CONTENT-TYPE?

java - GWT 事件 : what am i missing?

android - 在 Android 设备上使用 Vulkan 播放视频

java - 带有osmdroid的osm map 中的标记

java - 无法通过 Olap4J API 连接到 OLAP Cube

java - GAE JDO 中的奇数 id 序列