Osmdroid 离线 zip 文件(图块)地图无法在 Android 10 和 11 设备上加载

发布于 2025-01-20 21:51:52 字数 3394 浏览 2 评论 0 原文

我正在离线模式下使用osmdroid地图。我已经使用全局映射器下载了瓷砖,并且Zip Tiles保留在下载文件夹中(/sdcard/download)。 但是,在访问osmdroid的存档filefactory中,它的访问量低于错误。它发生在Android 10及以上。。给定存储访问权限。

ArchiveFileFactory类。在突出显示的行上获得错误,

”在此处输入图像描述”

在访问zip文件上获取错误:

Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.osmdroid.tileprovider.modules.ZipFileArchive.toString()

以下是代码:

使用权限

下面

和build.gradle config在

OSM库:

enter image description here

Tried Both Permissions :

1.Intent.ACTION_OPEN_DOCUMENT_TREE

2.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION

< a href =“ https://i.sstatic.net/y5ath.png” rel =“ nofollow noreferrer”>

离线图获取

    File f = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DOWNLOADS) + "/map_file.zip");
    if (f.exists()) {
        String name = f.getName().toLowerCase();
        name = name.substring(name.lastIndexOf(".") + 1);
        if (ArchiveFileFactory.isFileExtensionRegistered(name)) {
            try {
                OfflineTileProvider tileProvider = new OfflineTileProvider(new SimpleRegisterReceiver(getActivity()),
                        new File[]{f});
                mMap.setTileProvider(tileProvider);
                String source;
                IArchiveFile[] archives = tileProvider.getArchives();
                if (archives.length > 0) {
                    String mapSrc = Preference.getMapSrc(getContext());
                    if (TextUtils.isEmpty(mapSrc)) {
                        Set<String> tileSources = archives[0].getTileSources();
                        if (!tileSources.isEmpty()) {
                            source = tileSources.iterator().next();
                            Preference.setMapSrc(getContext(), source);
                            mMap.setTileSource(FileBasedTileSource.getSource(source));
                        } else {
                            mMap.setUseDataConnection(true);
                            mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
                        }
                    } else {
                        mMap.setTileSource(FileBasedTileSource.getSource(mapSrc));
                    }
                } else {
                    mMap.setUseDataConnection(true);
                    mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
                    return Constant.MAP_ASSETS_KML;
                }
                clearData();
                return Constant.MAP_ASSETS_KML;

            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    return Constant.MAP_ASSETS_KML;
}

I'm working with osmdroid map in offline mode. I have downloaded tiles using Global mapper and zip tiles are keep in download folder(/sdcard/Download). But on Accessing it getting below error in ArchiveFileFactory of osmdroid. It is Occurring in Android 10 and above.. Given storage access permission also.

ArchiveFileFactory class. Getting Error on highlighted line,

enter image description here

Getting Error On Access Zip File:

Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.osmdroid.tileprovider.modules.ZipFileArchive.toString()

Below is the code:

Permissions using
enter image description here

and build.gradle config is as below

enter image description here

Osm Library:

enter image description here

Tried Both Permissions :

1.Intent.ACTION_OPEN_DOCUMENT_TREE

2.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION

enter image description here

Fetching Offline Map

    File f = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DOWNLOADS) + "/map_file.zip");
    if (f.exists()) {
        String name = f.getName().toLowerCase();
        name = name.substring(name.lastIndexOf(".") + 1);
        if (ArchiveFileFactory.isFileExtensionRegistered(name)) {
            try {
                OfflineTileProvider tileProvider = new OfflineTileProvider(new SimpleRegisterReceiver(getActivity()),
                        new File[]{f});
                mMap.setTileProvider(tileProvider);
                String source;
                IArchiveFile[] archives = tileProvider.getArchives();
                if (archives.length > 0) {
                    String mapSrc = Preference.getMapSrc(getContext());
                    if (TextUtils.isEmpty(mapSrc)) {
                        Set<String> tileSources = archives[0].getTileSources();
                        if (!tileSources.isEmpty()) {
                            source = tileSources.iterator().next();
                            Preference.setMapSrc(getContext(), source);
                            mMap.setTileSource(FileBasedTileSource.getSource(source));
                        } else {
                            mMap.setUseDataConnection(true);
                            mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
                        }
                    } else {
                        mMap.setTileSource(FileBasedTileSource.getSource(mapSrc));
                    }
                } else {
                    mMap.setUseDataConnection(true);
                    mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
                    return Constant.MAP_ASSETS_KML;
                }
                clearData();
                return Constant.MAP_ASSETS_KML;

            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    return Constant.MAP_ASSETS_KML;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文