Upload Google Maps without internet - Android [closed]

0

I'm creating an app using google maps default activity in android studio, the application is already complete, but I'd like it to work without the internet, I've seen the google maps app has this functionality, but I have not seen any third parties doing this, is it possible? Does anyone have any information about it?

    
asked by anonymous 27.08.2016 / 16:48

1 answer

1

You can do this by using a class called TileProvider , which tries to create a collection of images displayed on the basic map blocks. So, there goes of creativity, you can record in the memory of the device or an SD card in .ZIP format. In this way, you can create a logic for every time there is no internet, consult this block of images to rebuild the map.

  

A TileOverlay defines a collection of images added on the   basic map blocks. You can also use block overlays   to add features to the map, providing block images   transparent. You need to supply the blocks for each zoom level   that you intend to offer. If you have enough blocks in   different zoom levels, you can supplement the map data from the   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 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:

  

TheGoogleMapsAPIdividesimagesfromeachzoomlevelintoone  setofsquaremapblocksarrangedinagrid.When  amapchangestoanewlocationortoanewzoomlevel,  MapsAPIdetermineswhichblocksarerequiredandconvertsthis  informationinasetofblockstoretrieve.

Thereisa OSMDROID project that supports native Java for Android and for Xamarim, which is already a push for you to work with Map offline. Please read more to find out and install the

27.08.2016 / 20:44