Click here to Skip to main content
11,921,731 members (67,689 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked

Custom Map Tiles (Android)

, 24 Sep 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple example of using custom tile server for Android maps using OSM (Open Street Map) library


In this article, I would like to show a simple example of using custom tile server for Android maps using OSM (Open Street Map) library.

Using the Code

Implementing custom tile sources is rather simple. First thing you need to do is to add open-street-map jar to your projects. For newbies:

A Best way to add External Jars to your Android Project or any Java project is:
  1. Create a folder called 'libs' into your project root folder
  2. Copy your Jar files to the libs folder
  3. Now right click on the Jar file and then select Build Path > Add to Build Path, this will create a folder called 'Referenced Library' into your project, and you are done

Here, you can find the latest version of osmdroid-android.jar.

Now don't forget to include Internet Permission to your Manifest file:

<uses-permission android:name="android.permission.INTERNET" /> 

and another one permission for tile provider to access network state:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

After you have successfully added library to your project, you need to implement TileSource. To do that, you simply have to create your class, let's say, called MyTileSource:

public MyTileSource(String aName, string aResourceId, int aZoomMinLevel, 
			int aZoomMaxLevel, int aTileSizePixels, 
			String aImageFilenameEnding, String[] aBaseUrl) { 
		super(aName, aResourceId, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels, 
				aImageFilenameEnding, aBaseUrl); 
	public String getTileURLString(MapTile aTile) { 
	return getBaseUrl() + "?request=getTile&apikey="+ MY_API_KEY +
         "&LayerName=E50931C3B2DD4E0FA2C03366552EEAA1" + "&z=" + aTile.getZoomLevel() + "&x=" + 
		aTile.getX() + "&y=" + aTile.getY(); 

The implementation is really simple. All you need is to override method getTileURLString.

In this method, you have to form the URL to your custom tile. Mine was something like

After that, you just need to set the TileSource of your map to your custom MyTileSource.

ITileSource _ITileSource = new MyTileSource("E50931C3B2DD4E0FA2C03366552EEAA1". null, 2, 13, 
256, "", "");  


I would be happy if I could help any of you in your work! Leave a comment, so I will try to improve my articles!

If you need the source code - it's available here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Belarus Belarus
Developing in C++, C#, .Net, Java, Delphi; working with SQL, HTML, JavaScript, CSS

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151120.1 | Last Updated 24 Sep 2012
Article Copyright 2012 by valeriyabobko
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid