Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to download offline Map with Qt

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "Qt how to realize offline map download". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "Qt how to realize offline map download" together.

I. Foreword

In fact, there are many kinds of offline map downloaders on the Internet, most of which are charged. Free ones either limit the number or level of tiles downloaded, or the tile map downloaded is watermarked. It looks very ugly. Because offline maps are often needed, I got rid of this limitation and specially spent some time re-studying the principle of tile maps and making an offline map downloader. In fact, tile map downloads are not so complicated. In fact, it is to set up the address of the tile map to be requested from several open server addresses. After sending the request, the image will be automatically returned to you. You only need to get the image data and save it as an image.

The tile map download process steps are as follows:

Get the scope of the visible area or administrative area

Get the latitude and longitude coordinates in the lower left corner of the area

Calculate the tile number of the corresponding level according to the level number

Automatically generate an address for downloading tile maps and issue a request

Parse the received data and save it as an image

Update the download quantity and progress of corresponding interface

You can select the corresponding saved directory, select all levels, stop downloading halfway, etc.

Choose whether to download street maps or satellite maps, etc.

II. Functional characteristics

Multi-thread synchronous download multi-level tile map, no card interface.

Built-in multiple offline map download request addresses, automatically randomly select a send request.

Download map types Support both street and satellite maps.

Automatically calculates the number of downloaded tiles in the visible area or administrative area.

The download level can be custom scoped and selected.

Signaling is sent when each tile is downloaded, with parameters including download time.

Maximum download timeout can be set. If it exceeds, the download task will be discarded and skipped to the next download task.

Displays download progress in real time, as well as the number of tiles downloaded and the total number of tiles at the current level.

Download process can stop downloading, download complete automatic statistics total time.

Built-in latitude and longitude and screen coordinate conversion function.

Baidu map is currently supported, other maps such as Google map, Tencent map, Gaode map can be customized.

Function interface friendly and unified, easy to use, on a class.

Support any Qt version, any system, any compiler.

III. Effect Drawing

void MapDownload::download(const QString &url, const QString &dirName, const QString &fileName, int zoom){ if (url.isEmpty()) { return; } //Start timer QTime time; time.start(); //First determine whether the folder exists, if it does not exist, create a new one QDir dir(dirName); if (! dir.exists()) { dir.mkpath(dirName); } //Local event loop, not stuck in main interface QEventLoop eventLoop; QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url))); connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit())); //Set download timeout QTimer timer; connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); timer.setSingleShot(true); timer.start(timeout); eventLoop.exec(); bool error = false; if (reply->bytesAvailable() > 0 && reply->error() == QNetworkReply::NoError) { //Read all data and save it as a file QByteArray data = reply->readAll(); QFile file(dirName + fileName); if (file.open(QFile::WriteOnly | QFile::Truncate)) { file.write(data); file.close(); } } else { //You can add download failure statistics by yourself error = true; qDebug()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report