8

I'm developing an android app using google maps android sdk v2 and want to allow users to download maps and use them offline.

  1. To display the tiles I use a custom TileProvider implementation as described here.
  2. I need to know the URL to download a google maps tile (vector tile if possible) based on latitude, longitude and zoom parameters (e.g. something like this )

Before anyone comments that it's violating google maps' terms, I can tell you it's ok to download a small amount of tiles specifically for this use case (see section 10.5.d in their terms here).

Community
  • 1
  • 1
BeFree
  • 469
  • 1
  • 7
  • 15

1 Answers1

18

This is the link

http://mt1.google.com/vt/lyrs=y&x=1325&y=3143&z=13

lyrs parameters are :

y = hybrid

s = satelite

t = train

m = map

By Overriding getTile in your TileProvider, You get the needed X and Y and Zoom. there is no need to do anything.

@Override
public Tile getTile(int x, int y, int zoom) {
    // DO YOUR STUFF HERE
}
Omid Heshmatinia
  • 5,089
  • 2
  • 35
  • 50
  • 1
    Thank you! How do you calculate x y z? – BeFree May 17 '16 at 12:26
  • I tested it and it works, so your answer is accepted - thank you @Smartiz. However, when speaking to a local google maps rep he told me using this method to implement offline maps is violating their terms, so I guess I will use a different map provider – BeFree May 20 '16 at 08:49
  • 1
    it works great ! as per my requirements , is there any way to download all the map tiles of a region at once ? – Gurpreet Kaur Jan 21 '18 at 10:11
  • i don't know any method for that. I think you should do it manually. @GurpreetKaur – Omid Heshmatinia Jan 21 '18 at 10:33
  • 7
    Formula to get x,y is: n = 2 ^ zoom; xtile = n * ((lon_deg + 180) / 360); ytile = n * (1 - (log(tan(lat_rad) + sec(lat_rad)) / π)) / 2; – dr ganjoo Feb 24 '19 at 18:28
  • @drganjoo I'm not getting the expected results out of this formula. What should be the base of the logarithm? – tuket Oct 17 '22 at 12:50
  • Got it working! Looks like it's natural logarithm. I made this python [code snippet](https://gist.github.com/tuket/1bc37ee7566d4af3ae14fb4ccbaed083). – tuket Oct 17 '22 at 13:52