Downloading/Caching Google Maps for Offline Use
Is it only possible to do this via the Google Maps 5 application and not the API without violating the ToS?
Correct, though AFAIK it's not even physically possible with the API.
How to cache Google map tiles for offline usage?
Unfortunately, I found this link which appears to indicate that we cannot cache these locally, therefore making this question moot.
http://support.google.com/enterprise/doc/gme/terms/maps_purchase_agreement.html
4.4 Cache Restrictions. Customer may not pre-fetch, retrieve, cache, index, or store any Content, or portion of the Services with the exception being Customer may store limited amounts of Content solely to improve the performance of the Customer Implementation due to network latency, and only if Customer does so temporarily, securely, and in a manner that (a) does not permit use of the Content outside of the Services; (b) is session-based only (once the browser is closed, any additional storage is prohibited); (c) does not manipulate or aggregate any Content or portion of the Services; (d) does not prevent Google from accurately tracking Page Views; and (e) does not modify or adjust attribution in any way.
So it appears we cannot use Google map tiles offline, legally.
Use google maps offline maps (cache) in Google Maps Android API
You need to create your own TileProvider
and access tiles locally. Check this documentation.
Here are some related threads that may help you:
- Using the android Google Maps API v2 as a viewer of offline tiles: is it possible?
- Offline mode for android app using google maps api
- TileProvider using local tiles
Check this video tutorial about caching and this example from GitHub.
You can also use osmdroid which is a replacement for Android's MapView class. It also includes a modular tile provider system with support for numerous online and offline tile sources and overlay support with built-in overlays for plotting icons, tracking location, and drawing shapes. Here is the tutorial.
org.osmdroid.views.MapView mapView = (org.osmdroid.views.MapView) findViewById(R.id.map_view); //resolve the map view by id given in the layout
mapView.setTileSource(new OnlineTileSourceBase("Google Maps", ResourceProxy.string.unknown, 1, 20, 256, ".png", "http://mt3.google.com/vt/v=w2.97") {
@Override
public String getTileURLString(final MapTile aTile) {
/*
* GOOGLE MAPS URL looks like
* base url const x y zoom
* http://mt3.google.com/vt/v=w2.97&x=74327&y=50500&z=17
*/
return getBaseUrl() + "&x=" + aTile.getX() + "&y=" + aTile.getY() + "&z=" + aTile.getZoomLevel();
}
});
mapView.setUseDataConnection(false); //this actually makes the controller use only offline tiles
Hope this helps!
How to cache/download google map v2 tile programmatically?
According this 10.1.3(b) you can do it temporally on mobile device.
This project implement it, I can't provide particular example but you can dig in into it coz it open-source.
Save google map for offline use
I have one solution. We can save map as tiles using UrlTileProvider. It saves the map tiles, based on the zooming level and x and y axis covered area in your screen.
TileProvider tileProvider = new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
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);
}
}
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 = map.addTileOverlay(new TileOverlayOptions()
.tileProvider(tileProvider));
Related Topics
Android Background Drawable Not Working in Button Since Android Studio 4.1
How to Share Image + Text Together Using Action_Send in Android
Android: Notifydatasetchanged(); Not Working
What's the Maximum Size for an Android Shared Preference Value
Value of a Global Variable Is Reset After It Is Initialised in Valueeventlistener
Are Parameters in Strings.Xml Possible
Gradle and Multi-Project Structure
Android: Capturing the Return of an Activity
Determine When a Viewpager Changes Pages
Httpurlconnection Worked Fine in Android 2.X But Not in 4.1: No Authentication Challenges Found
Android: Setselection Having No Effect on Spinner
Downloading/Caching Google Maps for Offline Use
Set Actionbar Tabs at Bottom in Actionbaractivity
Android Recyclerview Findviewholderforadapterposition Returns Null
How to Show Toast in Asynctask in Doinbackground
Extract Black and White Image from Android Camera's Nv21 Format