Here Wego: Offline Maps & Gps

      22
Offline Maps

With preloaded offline maps you can access whole countries or even continents completely offline without using any mạng internet connection or consuming OTA bandwith.

Bạn đang xem: Here wego: offline maps & gps

Offline maps offer the same features as the maps data that is available online: You can tìm kiếm for places, calculate routes, start guidance (only available for the Navigate Edition), & - of course - you can interact with the maps in the same way as with online map data.


This is a beta release of this feature, so tanhhungxadieu.vn could be a few bugs và unexpected behaviors. APIs may change for new releases without a deprecation process. Currently, only car routes are supported.


Why use offline maps? Tanhhungxadieu.vn can be situations when an mạng internet connection may lag, drop - or is completely off for a longer time. Especially, while on-the-go, a stable connection may not always be available. A smartphone device may also be offline due lớn the user"s decision khổng lồ save bandwidth. This means: Tanhhungxadieu.vn can be multiple reasons khổng lồ use offline maps - and last but not least, offline maps will tốc độ up the user"s experience with unbeatable response times. However, in most situations - when limited bandwidth and data consumption is not an issue - accessing online map data offers more accurate and up-to-date map data. Also, some features may not be available on offline maps, for example, tìm kiếm results may contain not all data that is available online.

You have two ways lớn access map data offline:

Offline Maps: With offline maps you can download entire regions or even continents to lớn preload their bản đồ data for offline use - including places, routing và other data. A dedicated MapDownloader enables you to get & to maintain this data. Offline maps data is persisted between sessions và the data will not be deleted unless the user decides so. In this section, we describe how this works.

Offline maps work for all map schemes that are vector based. Satellite based maps schemes are not part of the downloaded bản đồ data.

Good to lớn know:

While interacting with a maps view, the anhhungxadieu.vn SDK will first check if downloaded offline map data is available và show it. If no offline maps are available for the current target, the anhhungxadieu.vn SDK will download online map data & cache it. If no online connection is available, it will try to lớn find data in the map data cache. If even that fails, the bản đồ will be shown with less details or even no details.

When the anhhungxadieu.vn SDK uses backend services such as for tìm kiếm and routing, you need khổng lồ use dedicated offline engines to access cached or predownloaded offline bản đồ data. Use the OfflineSearchEngine và OfflineRoutingEngine to lớn access maps data offline. Their counterparts, the SearchEngine and RoutingEngine, will only provide results when an online connection is available - otherwise you will get an error. Tanhhungxadieu.vnfore, you need lớn decide which engine to lớn use.

Overview

Downloading and using offline maps can be achieved in two simple steps.

1) tải về a menu of Region objects. Optionally, this menu can be localized with local region names. Once you have this list, you can pick the RegionId you want to download and pass it as tải về request lớn the MapDownloader.

2) Use the MapDownloader to download a single Region or a danh sách of regions. You can also download several regions in parallel. Show the download progress to lớn the user by setting a DownloadRegionsStatusListener.

Once the tải về has completed, the bản đồ is ready khổng lồ be used. If a device is offline, it will automatically show the downloaded region when the camera"s target is pointed khổng lồ that region.

If a tải về failed, the anhhungxadieu.vn SDK will still be in a fully operable state. Just try to tải về again, until the progress has reached 100% & the status finally indicated that the operation has completed. Cảnh báo that, currently, map data can only be deleted manually from the device"s storage.

Since maps data for regions, countries or whole continents can contain several hundreds of megabytes, a tải về may take a while - depending on factors such as available bandwidth. A tải về may also fail, when a connection gets timed out and cannot recover. For best user experience, it is recommended to lớn allow the user to lớn cancel ongoing operations and to watch the progress until a bản đồ download succeeds.

Xem thêm: Râu Đen Blackberry Passport Silver Edition Mua Râu Đen, Nổi Tiếng Với Độ Bảo Mật Tuyệt Vời


To get a quick overview of how all of this works, you can take a look at the OfflineMapsExample class. It contains all code snippets shown below & it is part of the OfflineMaps example app you can find on GitHub.


Create a MapDownloader Instance

You can create the MapDownloader once per SDKNativeEngine:

SDKNativeEngine sdkNativeEngine = SDKNativeEngine.getSharedInstance();if (sdkNativeEngine == null) throw new RuntimeException("SDKNativeEngine not initialized.");mapDownloader = MapDownloader.fromEngine(sdkNativeEngine); Usually, the SDKNativeEngine is automatically initialized when you start the phầm mềm to show a MapView. Tanhhungxadieu.vnfore, you can access it"s instance at runtime và obtain the MapDownloader from it.

By default, the downloaded maps data will be stored to a default location:

// lưu ý that the default storage path can be adapted when creating a new SDKNativeEngine.String storagePath = SDKNativeEngine.getSharedInstance().getOptions().cachePath;Log.d("", "StoragePath: " + storagePath); As stated in the comment, you can change that storage location, if you wish so - but then you need khổng lồ create a new SDKNativeEngine instance as shown in the Key Concepts section and set the new cache path together with your credentials as part of the SDKOptions. Lưu ý that the storage path is quality for your credentials key.

download a các mục of Regions

Each downloadable Region is identified by a chất lượng RegionId. In order lớn know, which regions are available and which RegionID belongs lớn which Region, you need to tải về a list of all available offline maps. This contains regions from the entire world.

Each Region can contain multiple children và each child represents a subset of its parent Region - when you tải về the parent, then the child regions are automatically included. If you are interested only in smaller portions of an area you can traverse the child regions. Usually, the top-level regions represent continents with countries as children. For the sake of simplicity, below we only look for downloadable countries & ignore any children of children và their children (and so on).

The code below downloads the menu of downloadable regions & stores the available Region elements in a danh sách for later use:

// tải về a danh mục of Region items that will tell us what map regions are available for later download.mapDownloader.getDownloadableRegions(LanguageCode.DE_DE, new DownloadableRegionsCallback()
Nullable ListRegion> list) if (mapLoaderError != null) String message = "Downloadable regions error: " + mapLoaderError; snackbar.setText(message).show(); return; // If error is null, it is guaranteed that the các mục will not be null. DownloadableRegions = list; for (Region region : downloadableRegions) Log.d("RegionsCallback", region.name); ListRegion> childRegions = region.childRegions; if (childRegions == null) continue; // chú ý that this code ignores to danh sách the children of the children (and so on). For (Region childRegion : childRegions) long sizeOnDiskInMB = childRegion.sizeOnDiskInBytes / (1024 * 1024); String logMessage = "Child region: " + childRegion.name + ", ID: "+ childRegion.regionId.id + ", Size: " + sizeOnDiskInMB + " MB"; Log.d("RegionsCallback", logMessage); String message = "Found " + downloadableRegions.size() + " continents with various countries. See log for details."; snackbar.setText(message).show(); ); The response contains either an error or a result: MapLoaderError and ListRegion> can never be null at the same time - or non-null at the same time.

Each region can contain child regions. For example, Europe contains Germany, France và Switzerland - và many more child regions. The sizeOnDiskInBytes parameter tells you how much space the downloaded bản đồ will occupy on the device"s file system when it"s uncompressed after download has completed. It makes sense khổng lồ show this to the user before starting the tải về - as the available space on a device may be limited.

*
Screenshot: Showing an example how downloadable maps could be indicated khổng lồ users.

download a Region

Once you know the RegionId, you can use it khổng lồ start downloading the map data. Each Region instance contains a localized name & other data, such as the size of the downloaded map. When the maps data is downloaded, all data is compressed & will be unpacked automatically onto the device"s disk once the download is complete.

Below we tìm kiếm the downloaded danh mục of regions lớn find the Region element for Switzerland. Note that we have requested the region list to be localized in German in the step above:

// Finds a region in the downloaded region list.// chú ý that we ignore children of children (and so on).private Region findRegion(String localizedRegionName) Region downloadableRegion = null; for (Region region : downloadableRegions) if (region.name.equals(localizedRegionName)) downloadableRegion = region; break; ListRegion> childRegions = region.childRegions; if (childRegions == null) continue; for (Region childRegion : childRegions) if (childRegion.name.equals(localizedRegionName)) downloadableRegion = childRegion; break; return downloadableRegion; Once we know the Region, we can use it"s RegionId to start the download. We pass the unique ID into a list, so we can tải về multiple regions with the same request. anhhungxadieu.vn, we download only one region:

// Find region for Switzerland using the German name as identifier.// cảnh báo that we requested the menu of regions in German above.String swizNameInGerman = "Schweiz";Region region = findRegion(swizNameInGerman);if (region == null ) String message = "Error: The Swiz region was not found. Click "Regions" first."; snackbar.setText(message).show(); return;// For this example we only tải về one country.ListRegionId> regionIDs = Collections.singletonList(region.regionId);MapDownloaderTask mapDownloaderTask = mapDownloader.downloadRegions(regionIDs, new DownloadRegionsStatusListener()
Nullable ListRegionId> list) if (mapLoaderError != null) String message = "Download regions completion error: " + mapLoaderError; snackbar.setText(message).show(); return; // If error is null, it is guaranteed that the các mục will not be null. // For this example we downloaded only one hardcoded region. String message = "Completed 100% for Switzerland! ID: " + list.get(0).id; snackbar.setText(message).show();
NonNull RegionId regionId, int percentage) String message = "Download for Switzerland. ID: " + regionId.id + ". Progress: " + percentage + "%."; snackbar.setText(message).show();
Nullable MapLoaderError mapLoaderError) if (mapLoaderError == null) String message = "The download was paused by the user calling mapDownloaderTask.pause()."; snackbar.setText(message).show(); else String message = "Download regions onPause error. The task tried to often to retry the download: " + mapLoaderError; snackbar.setText(message).show();
Override public void onResume() String message = "A previously paused tải về has been resumed."; snackbar.setText(message).show(); );mapDownloaderTasks.add(mapDownloaderTask); The DownloadRegionsStatusListener provides four events. The second one tells us the progress while the tải về is ongoing, while the first one notifies once the tải về has completed. Cảnh báo that the tải về can also complete with a MapLoaderError, so it"s worth to check if something went wrong.

The response for onDownloadRegionsComplete() contains either an error or a result: MapLoaderError & ListRegionId> can never be null at the same time - or non-null at the same time.

The pause event notfies when a download was paused by the user or the task itself. Internally, the anhhungxadieu.vn SDK will retry to tải về a region when it was interrupted, ie. Due to lớn a bad network connection. If this happens too often, the MapLoaderError for onPause() is populated & the download pauses. A paused MapDownloaderTask can only be resumed by the user, which will be also indicated by the related event. Especially for larger regions it may be convenient khổng lồ pause a download until the connection gets better, for example. When resumed, the download will continue at the progress wanhhungxadieu.vn it stopped và no already downloaded map data will be lost. Cảnh báo that calling downloadRegions() for a paused region will have the same effect as calling resume() on the original task và the progress will continue wanhhungxadieu.vn it left off.

After kicking off the download, we get an immediate return value khổng lồ be able to cancel the ongoing asynchronous tải về operation. Above, we store the MapDownloaderTask into a list, as a user might trigger the above code multiple times.

To cancel all ongoing downloads, you can use the following code snippet:

public void onCancelMapDownloadClicked() for (MapDownloaderTask mapDownloaderTask : mapDownloaderTasks) mapDownloaderTask.cancel(); String message = "Cancelled " + mapDownloaderTasks.size() + " tải về tasks in list."; snackbar.setText(message).show(); mapDownloaderTasks.clear(); note that a MapDownloaderTask that was cancelled cannot be resumed again, but you can start a fresh download request again.

Win79 - Game Bài Đẳng Cấp Vượt Thời Đại