Offline Mapping
Last updated
Was this helpful?
Last updated
Was this helpful?
Using maps without an Internet connection is common requirement. Luckily, there are a few options available to you to implement offline mapping in your app.
Automatically store tiles as the user loads them through interacting with the map, usually on a temporary basis
Download an entire area/region of tiles in one shot, ready for a known no-Internet situation
Provide a set of pre-determined tiles to all users through app assets or the filesystem
This section contains references to as-of-yet unreleased versions and unconfirmed features.
Caching is used usually to improve user experience by reducing network waiting times, not necessarily to prepare for no-Internet situations. Caching can be more temporary (eg. in-memory/session-only, where the cache is cleared after the app is closed), or more long-term (eg. app cache, where the OS takes responsibility for clearing the app cache when necessary/when requested).
Many tile servers, such as the OpenStreetMap tile server, will require you to implement longer-term caching!
Since v8.2.0, flutter_map provides Built-In Caching. This satisfies many requirements of both users and tile servers automatically.
If you'd prefer not to use built-in caching, you can:
Try another MapCachingProvider
implementation if you still only need simple caching
These are compatible with the standard NetworkTileProvider
(and cancellable version), as with built-in caching, but use a different storage mechanism.
You can create an implementation yourself, or use one provided by a 3rd-party/plugin. See for more info.
Use a caching HTTP client
NetworkTileProvider.httpClient
can be used to set a custom HTTP client. Some packages, such as '', offer clients which perform HTTP caching, similar to built-in caching.
Use a different TileProvider
Tile providers have full control over how a tile is generated to be displayed, and so there are many possibilities to integrate caching.
Create a with a caching ImageProvider
(either custom or using a package such as '')
Use Caching created prior to built-in caching, lightweight and MIT licensed, but with more pre-provided options than built-in caching through 3rd-party storage implementations
Use Supports very advanced caching use-cases and Bulk Downloading, but GPL licensed
You must comply with the appropriate restrictions and terms of service set by your tile server. Always read the ToS before using a tile server. Failure to do so may lead to any punishment, at the tile server's discretion. Many tile servers will forbid or restrict bulk downloading, as it places additional strain on their servers.
Bulk downloading is used to prepare for known no-Internet situations by downloading map tiles, then serving these from local storage.
Bulk downloading is more complex than Caching, especially for regions that are a non-rectangular shape. Implementing this can be very time consuming and prone to issues.
If you have a set of custom raster tiles that you need to provide to all your users, you may want to consider bundling them together, to make a them easier to deploy to your users. Bundles can be provided in two formats.
Container formats, such as the traditional MBTiles, or the more recent PMTiles, store tiles usually in a database or binary internal format.
These require a special parser to read on demand, usually provided as a TileProvider
by a plugin. The following community-maintained plugins are available to read these formats:
When uncontained, tiles are usually in a tree structure formed by directories, usually 'zoom/x/y.png'. These don't require special parsing, and can be provided directly to the TileLayer
using one of the built-in local TileProvider
s.
AssetTileProvider
You can ship an entire tile tree as part of your application bundle, and register it as assets in your app's pubspec.yaml.
This means that they will be downloaded together with your application, keeping setup simple, but at the expense of a larger application bundle size.
If using AssetTileProvider
, every sub-directory of the tree must be listed seperately. See the example application's 'pubspec.yaml' for an example.
FileTileProvider
This allows for more flexibility: you could store a tile tree on a remote server, then download the entire tree later to the device's filesystem, perhaps after intial setup, or just an area that the user has selected.
This means that the setup may be more complicated for users, and it introduces a potentially long-running blocking action, but the application's bundle size will be much smaller.
The includes advanced bulk downloading functionality, of multiple different region shapes, and other functionality. It is however GPL licensed. To help choose whether FMTC or DIY is more appropriate for your use case, please see:
: (when using vector tiles)
: ( when using vector tiles, also works in online contexts)