Using osmdroid without getting access to external storage

荒凉一梦 提交于 2019-11-29 13:53:23

https://github.com/osmdroid/osmdroid/wiki/FAQ

Fresh off the wiki press. Yes you can change the location to application private storage, in which case it should work just fine. Pro tip: set these before loading any map views.

OpenStreetMapTileProviderConstants.setCachePath(...) OpenStreetMapTileProviderConstants.setCacheSizes(...) OpenStreetMapTileProviderConstants.setOfflineMapsPath(...) OpenStreetMapTileProviderConstants.setUserAgentValue(...)

Update: Newer versions of osmdroid, starting in 5.6 and up use the following

Configuration.getInstance().setCachePath(...) Configuration.getInstance().setCacheSizes(...) Configuration.getInstance().setOfflineMapsPath(...) Configuration.getInstance().setUserAgentValue(...)

For solving this problem I just added into my application class next code:

        @Override
            public void onCreate() {
            ...
            org.osmdroid.config.IConfigurationProvider osmConf = org.osmdroid.config.Configuration.getInstance();
            File basePath = new File(getCacheDir().getAbsolutePath(), "osmdroid");
            osmConf.setOsmdroidBasePath(basePath);
            File tileCache = new File(osmConf.getOsmdroidBasePath().getAbsolutePath(), "tile");
            osmConf.setOsmdroidTileCache(tileCache);
            ...
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!