I'm developing an android app using google maps android sdk v2 and want to allow users to download maps and use them offline.
To display the tiles I use a custom TileProvider implementation as described here.
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).
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
}
Related
I've downloaded map tiles from http://tile.openstreetmap.org. What I want to do is use this map tiles with google map Library. I've followed the this links
- How to show google map offline?
- Google Map Offline
- TileProvider using local tiles
And have working map activity.
Here is CustomTileProvider class
public class CustomTileProvider implements TileProvider{
public Tile getTile(int x, int y, int zoom) {
Log.e("TAG","Get tile image");
byte[] image = readTileImage(x, y, zoom);
}
}
The problem I'm currently facing is when I uninstall the app and install, and run whithout internet connect the getTile method never been called. Can any body know why this is happening?
Edit:
I've stored the downloaded tiles inside assets folder with the following file structure
/map
/zoom/
/x
/y
I was just wondering as to how to draw route direction(two point) of Google Maps in order for it to work offline. We have already downloaded offline Google Maps and then want navigation but do not know how to.
I was thinking of creating a navigation system with offline Google Maps, but I don't know how to draw route direction offline Google Map to work offline then embed it within my own application.
I have already used #mapbox Sdk, but my issue was I have downloaded offline location in Google Maps, after this location search any direction used two point direction in map, so I can drawline easily.
Using this : https://www.mapbox.com/android-sdk/examples/offline-manager/
Please help me on this one..
Could you clarify how exactly you are getting Google Directions API to work offline, to my knowledge the API only works online? Drawing the route can be done in a few different ways. The simpliest would be to convert the linestring the directions API gives you into multiple positions and then feed them into the polyline:
private void drawRouteLine(DirectionsRoute route) {
List<Position> positions = LineString.fromPolyline(route.getGeometry(), Constants.PRECISION_6).getCoordinates();
List<LatLng> latLngs = new ArrayList<>();
for (Position position : positions) {
latLngs.add(new LatLng(position.getLatitude(), position.getLongitude()));
}
routeLine = mapboxMap.addPolyline(new PolylineOptions()
.addAll(latLngs)
.color(Color.parseColor("#56b881"))
.width(5f));
}
I am developing an android mapping app using OSMDroid. I am attempting to use free custom aerial imagery, completely independent of google and/or bing api's. Please, do not propose ANY solution that uses their mapping api's.
I have managed to display satellite imagery by including this code:
mapView.setTileSource(TileSourceFactory.MAPQUESTAERIAL);
BUT, tile server does not offer tiling above 11 zoom and i need to get wee closer than that (say 15-16?).
Using ARCGis tile server, I manage to display satellite imagery even to 16 layer zoom level, but tiles are shuffled around.
mapControl = (MapController) mapView.getController();
mapControl.setZoom(11);
String[] urlArray = {"http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/"};
mapView.setTileSource(new XYTileSource("ArcGisOnline", null, 0, 18, 256, ".png",urlArray ));
Basemap tiles are shuffled and do not correspond to lat/lon, but overlay is ok.
The tile server probably uses a different scheme for retrieving tiles. Try flipping the X and Y coordinates. Slippy map servers (osm) use the Z/X/Y.ext format. ArgGis and several others use Z/Y/X.ext format. All other coordinates are the same. This means the solution is simple, override the getTileURLString method and supply the coordinates in whatever format the server wants.
Osmdroid has an example for doing exactly this.
https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/SampleCustomTileSource.java
The relevant bit a code this
mMapView.setTileSource(new OnlineTileSourceBase("USGS Topo", 0, 18, 256, "",
new String[] { "http://basemap.nationalmap.gov/ArcGIS/rest/services/USGSTopo/MapServer/tile/" }) {
#Override
public String getTileURLString(MapTile aTile) {
return getBaseUrl() + aTile.getZoomLevel() + "/" + aTile.getY() + "/" + aTile.getX()
+ mImageFilenameEnding;
}
});
You'll also want to purge the cache after this change since it has the wrong coordinates
I am really new in this routing and maps area. I have a basic, maybe stupid, question. I use osmdroid to show a tile from a URL that looks like this
http://tile01-cdn.maptoolkit.net/terrain/15/17789/11515.png
Where 15 represents the zoom,
17789 the X value and
11515 the Y value
Now when I want to use osmdroid to show this tile in the map I don't know what kind of TileSource should I use. The most obvious is the XYTileSource but the constructor does not have any x y parameters to pass, but I see on the internet a lot of questions/answers where people use the same object but with a different constructor. I am guessing here that the code has changed in the lib. The current constructor:
XYTileSource(String aName, int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels, String aImageFilenameEnding, String[] aBaseUrl)
So my question is how can I show this tile map of mine in the osmdroid map, what kind of ITileSource should I use? Should I implement my own custom one?
this is how I tried to do it:
final ITileSource tileSource = new XYTileSource("Maverik", 15, 17789, 11515, ".png", new String[] {"http://tile01-cdn.maptoolkit.net/terrain/"});
tileProvider.setTileSource(tileSource);
and I get an empty MapView.
Purpose of osmdroid is to display world map - with a lot of tiles. And to display the appropriate tiles depending on where the "map view" is centered (this center being defined with: a latitude, a longitude, and a zoom level).
If this is also what you want:
1) As examples, look at default tile sources included in osmdroid, in TileSourceFactory
2) Then you could try something like:
OnlineTileSourceBase tileSource = new XYTileSource("Maverik",
0, 17,
256, ".png",
new String[] {
"http://tile01-cdn.maptoolkit.net/terrain/",
"http://tile02-cdn.maptoolkit.net/terrain/",
"http://tile03-cdn.maptoolkit.net/terrain/"
});
mapView.setTileSource(tileSource);
You may also want ton consult the osmdroid wiki and the source for the sample application. There's tons of examples on how to use just about every tile source that we know of. We're also adding more as they are discovered.
https://github.com/osmdroid/osmdroid/wiki
You don't need to worry about X and Y coordinates. They actually aren't lat/lon coordinates but are grid references. Open Street Maps, and many other tile sources, use the same or similar tile coordinate system. Start with the world in one image. Zoom =1 divide it into 4 parts. That's your X,Y and Zoom coordinates. Zoom =2 level, divid the four tiles we started with into 4 again, and we have 16 tiles.
I am working on custom map app and i want to use google map tiles for background ? There is one class TileProvider in api but i don't know how to initialize it every time i try it goes something like this ?
TileProvider tileProvider=new TileProvider() {
#Override
public Tile getTile(int i, int i2, int i3) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
};
how to override getTile function to get tiles from google map server?
Any example will be appreciated ?I know getTile function need x,y and zoom value to return tile.
So quick answer is that you can get the Google Map tiles from the following URL:
http://mt1.google.com/vt/lyrs={t}&x={x}&y={y}&z={z}
Where {t} is the type of map (satellite, road, hybrid, etc) and the other attributes are specifying the coordinates and zoom level.
The possible values for {t} are as follows:
Default - m
Roads only - h
Roads simplified - r
Satellite - s
Satellite hybrid - y
Terrain - t
Terrain hybrid - p
That being said you do want to make sure what you're doing is NOT a violation of the terms & services. Specifically Google WILL allow you to cache their tiles provided that you are doing so ONLY in order to improve performance and that you delete their tiles at least every 30 days, and finally you don't pull down their tiles in an attempt to make your own mapping service.
You may want to read the Google Maps Terms of Service - https://developers.google.com/maps/terms - specifically section 10.1.1