Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. GoogleMap map; // ... declara um mapa
  2. TileProvider tileProvider; // ... cria um tile provider
  3. TileOverlay tileOverlay = map.addTileOverlay(
  4. new TileOverlayOptions().tileProvider(tileProvider));
  5.  
  6. TileProvider tileProvider = new UrlTileProvider(256, 256) {
  7. @Override
  8. public URL getTileUrl(int x, int y, int zoom) {
  9.  
  10. /* Define the URL pattern for the tile images */
  11. String s = String.format("http://my.image.server/images/%d/%d/%d.png",
  12. zoom, x, y);
  13.  
  14. if (!checkTileExists(x, y, zoom)) {
  15. return null;
  16. }
  17.  
  18. try {
  19. return new URL(s);
  20. } catch (MalformedURLException e) {
  21. throw new AssertionError(e);
  22. }
  23. }
  24.  
  25. /*
  26. * Check that the tile server supports the requested x, y and zoom.
  27. * Complete this stub according to the tile range you support.
  28. * If you support a limited range of tiles at different zoom levels, then you
  29. * need to define the supported x, y range at each zoom level.
  30. */
  31. private boolean checkTileExists(int x, int y, int zoom) {
  32. int minZoom = 12;
  33. int maxZoom = 16;
  34.  
  35. if ((zoom < minZoom || zoom > maxZoom)) {
  36. return false;
  37. }
  38.  
  39. return true;
  40. }
  41. };
  42.  
  43. TileOverlay tileOverlay = mMap.addTileOverlay(new TileOverlayOptions()
  44. .tileProvider(tileProvider));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement