Can you do this using a class called TileProvider
, which deals with creating a collection of images displayed on the blocks of the basic map. So, there goes creativity, you can write in the device memory or an SD card in format .ZIP. This way, you can create a logic for every time there is no internet, consult this block of images to rebuild the map.
One TileOverlay
sets a collection of images added over
basic map blocks. It is also possible to use block overlays
to add features to the map by providing block images
transparent. Blocks need to be provided for each zoom level
that you intend to offer. If you have enough blocks in
different zoom levels, can complement the map data of
Google for the full map.
Example:
GoogleMap map; // ... declara um mapa
TileProvider tileProvider; // ... cria um tile provider
TileOverlay tileOverlay = map.addTileOverlay(
new TileOverlayOptions().tileProvider(tileProvider));
Calling the GoogleMap.addTileOverlay()
:
TileProvider tileProvider = new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
/* Define the URL pattern for the tile images */
String s = String.format("http://my.image.server/images/%d/%d/%d.png",
zoom, x, y);
if (!checkTileExists(x, y, zoom)) {
return null;
}
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
/*
* Check that the tile server supports the requested x, y and zoom.
* Complete this stub according to the tile range you support.
* If you support a limited range of tiles at different zoom levels, then you
* need to define the supported x, y range at each zoom level.
*/
private boolean checkTileExists(int x, int y, int zoom) {
int minZoom = 12;
int maxZoom = 16;
if ((zoom < minZoom || zoom > maxZoom)) {
return false;
}
return true;
}
};
TileOverlay tileOverlay = mMap.addTileOverlay(new TileOverlayOptions()
.tileProvider(tileProvider));
This image describes a little what happens:
The Google Maps API divides the images of each zoom level into one
set of square map blocks, organized in a grid. When
a map changes to a new location or to a new zoom level,
the Maps API determines which blocks are needed and converts this
information in a set of blocks to recover.
There is a project OSMDROID that support for native Java for Android and for Xamarim, which is already a push for you to work with Offline Map. Take a read more to know about it and install the application Maps and Navigation - Osmand for you to have more notion of how it works.
Details
I imagine you have to download the map to your device, see if it helps: https://support.google.com/maps/answer/6291838?co=GENIE.Platform%3DAndroid&hl=en
– Edson Santos