首页 > 解决方案 > 通过 QtLocation 插件使用离线数据

问题描述

我有 500mb 的离线数据想与 OSM QtLocation 插件一起使用。我使用了此博客https://www.qt.io/blog/2017/05/24/qtlocation-using-offline-map-tiles-openstreetmap-plugin中的示例源代码。示例应用程序中的数据嵌入在资源文件中,我想将它放在磁盘上的单独文件夹中。首先,我想让示例应用程序使用位于磁盘文件夹中的示例数据,而不是在资源文件中编译。执行应用程序时,它仍然从在线服务器下载数据。我在网上阅读了很多文章,但没有一个解决方案有效。我正在使用带有 MSVC 编译器的 Qt 5.15.2、Windows 10。

这就是我的代码的样子。

import QtQuick 2.7
import QtQuick.Window 2.2
import QtLocation 5.8

Window {
    id: win
    objectName: "window"
    visible: true
    width: 512
    height: 512

    Map {
        id: map
        anchors.fill: parent
        activeMapType: map.supportedMapTypes[1]
        zoomLevel: 1
        plugin: Plugin {
            id: osmPLugin
            name: 'osm';
            PluginParameter { name: 'osm.mapping.offline.directory'; value: 'file:///c:/offline_tiles/' }
        }
    }
}

标签: qtopenstreetmapofflineqtlocation

解决方案


您必须使用路径,而不是 uri:

PluginParameter { name: 'osm.mapping.offline.directory'; value: 'c:/offline_tiles/' }

推荐阅读