Click here to Skip to main content
13,045,379 members (123,223 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 22 Sep 2012

Custom Map Tiles (Android)

, 24 Sep 2012
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 --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Sep 2012
Article Copyright 2012 by valeriyabobko
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid