Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use google maps offline maps (cache) in Google Maps Android API

Google Maps offers for a few months the feature to download a certain geographic region for later offline use. I use Google Maps Android API in my App and I see that while offline, in contrast to the real google maps app, I cannot zoom in to street level in my App fully, so the downloaded data is probably not used.

Is there a way for my app to make use of it?

like image 856
Phil Avatar asked Jul 03 '16 10:07

Phil


People also ask

Can you cache Google Maps API?

Applications using the Places API are bound by the terms of your Agreement with Google. Subject to the terms of your Agreement, you must not pre-fetch, index, store, or cache any Content except under the limited conditions stated in the terms.

Can I use Google Maps offline on Android?

Now if your internet connection is slow or absent, Google Maps will use your offline map to give you driving directions. Important: You can only get driving directions offline and you won't get traffic info, alternate routes, or lane guidance.

Does Google offline maps save data?

Google Maps allows you to download maps for offline use, helping you save on mobile data when you're out and about. The option to save maps for later is especially helpful when network coverage is sparse — like when you are travelling or in a place with dampeners.


1 Answers

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!

like image 178
abielita Avatar answered Oct 19 '22 07:10

abielita