Stamen Maps on Android

Stamen makes a beautiful set of google map layers. I love the watercolor look, and using it on Android with native the native google maps engine is fairly straightforward. Grab the .zip file of my eclipse project to take a look.

I started with the hellomap starter project and this stackoverflow post. Most of the magic is in MainActivity.java:

package com.example.hellomap;
 
import java.net.MalformedURLException;
import java.net.URL;
 
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
 
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.TileOverlayOptions;
import com.google.android.gms.maps.model.UrlTileProvider;
 
public class MainActivity extends FragmentActivity {
    private GoogleMap mMap;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setUpMapIfNeeded();
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }
 
    private void setUpMapIfNeeded() {
        if (mMap == null) {
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        }
        if (mMap == null) {
            return;
        }
 
        mMap.setMapType(GoogleMap.MAP_TYPE_NONE);
        TileOverlayOptions options = new TileOverlayOptions();
        options.tileProvider(new UrlTileProvider(256, 256) {
            @Override
            public URL getTileUrl(int x, int y, int z) {
                try {
                    String f = "http://tile.stamen.com/watercolor/%d/%d/%d.jpg";
                    return new URL(String.format(f, z, x, y));
                }
                catch (MalformedURLException e) {
                    return null;
                }
            }
        });
 
        mMap.addTileOverlay(options);
 
        final LatLng TAIPEI = new LatLng(25.091075,121.559835);
        CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(TAIPEI)
            .zoom(12)
            .tilt(45)
            .build();
        mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
 
    }
 
}