Reputation: 693
I need to add a custom base layer to to my map view. My understanding is that the map tiles are exactly the same as the google tiles. They are static files served up in the following format: http:///tilecache///.png
For example, the http:///tilecache/6/16/26.png is the gulf coast between florida alabama and mississippi.
How do I create an overlay with the tiles?
Upvotes: 5
Views: 2230
Reputation: 6778
For newer versions of OSMDroid, the aResourceId parameter to the constructor has been removed and the last parameter, aBaseUrl, is a String[]
public YourTileSource (String aName,
int aZoomMinLevel,
int aZoomMaxLevel,
int aTileSizePixels,
String aImageFilenameEnding,
String[] aBaseUrl) {
super(aName,
aZoomMinLevel,
aZoomMaxLevel,
aTileSizePixels,
aImageFilenameEnding,
aBaseUrl);
}
Upvotes: 0
Reputation: 6193
osmdroid (as recommended above) is cool but quite huge. Some time ago I decided to use http://sourceforge.net/projects/libwlocate/ instead - it contains functionalities for showing/scrolling/zooming maps like osmdroid but you can choose to use OSM, Google Maps or Google satellite view.
An example how to use it can be found in http://libwlocate.git.sourceforge.net/git/gitweb.cgi?p=libwlocate/libwlocate;a=blob;f=master/android/LocDemo/src/com/vwp/locdemo/LocDemo.java;h=5e2134fb7d197258f5f4f6f9021d2fa9ad9f2d9a;hb=HEAD
Upvotes: 2
Reputation: 325
I would recommend using osmdroid. You can extend OnlineTileSourecBase.
public class YourTileSource extends OnlineTileSourceBase implements IStyledTileSource<Integer> {
public YourTileSource (String aName, string aResourceId,
int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels,
String aImageFilenameEnding, String aBaseUrl) {
super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels,
aImageFilenameEnding, aBaseUrl);
}
public void setStyle(Integer style) {
// TODO Auto-generated method stub
}
public void setStyle(String style) {
// TODO Auto-generated method stub
}
public Integer getStyle() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTileURLString(MapTile aTile) {
return getBaseUrl() + "/" + aTile.getX() + "/" + aTile.getY() + "/" + aTile.getZoomLevel() + ".png";
}
}
Then add your tile source to your mapview:
TileSourceFactory.addTileSource(new YourTileSource ("YourTileSource", null, 1, 20, 256, ".png", "http:///tilecache/"));
mapView.setTileSource(TileSourceFactory.getTileSource("YourTileSource"));
Your mapView needs to be an org.osmdroid.views.MapView for that to work. OSMdroid classes should replace all of the google maps classes.
Start by downloading the osmdroid-android-3.0.8.jar file, add it to your libs folder in your project, and then add it to the project through right click > Properties > Java Build Path > Libraries > Add Jars, and then find it in the libs folder. Post more questions if you have them, I have a lot of experience with osmdroid.
Upvotes: 1