Archive for January, 2012

URL Encoding for iOS

Posted: January 23, 2012 in iPhone Dev

[urlParam  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]


To remove the shadow just extend ItemizedOverlay and override this method.

public void draw( canvas,MapView mapView,boolean shadow) {

super.draw(canvas, mapView, false);


I am researching about "Offline map with custom tiles image" on android application.
These are some sample code about add ground overlay image as in Java Script API do.
public class GroundOverlay extends OverlayItem {

    private MapView map;
    private Bitmap overlay;
    private GeoPoint topGeoPoint;
    private GeoPoint bottomGeoPoint;

    public Drawable drawable;

    public GroundOverlay(
            MapView map, 
            GeoPoint topLeftGeoPoint, 
            GeoPoint bottomRightGeoPoint, 
            Bitmap overlay,
            String title, 
            String snippet) {
        super(bottomRightGeoPoint, title, snippet); = map;
        this.overlay = overlay;
        this.topGeoPoint = topLeftGeoPoint;
        this.bottomGeoPoint = bottomRightGeoPoint;


    private void _init() {
        Point topPoint = new Point();
        Point bottomPoint = new Point();

        map.getProjection().toPixels(topGeoPoint, topPoint);
        map.getProjection().toPixels(bottomGeoPoint, bottomPoint);

        int width = bottomPoint.x - topPoint.x;
        int height = bottomPoint.y - topPoint.y;

        drawable = overlayDrawable(overlay, width, height);

    public BitmapDrawable overlayDrawable(Bitmap bitmap, int newWidth, int newHeight) {
        Matrix scale = new Matrix();

        float scaleFloat = (float)newWidth / (float)bitmap.getWidth();

        scale.postScale(scaleFloat, scaleFloat);
        Bitmap bitmapScaled = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), scale, false);

        BitmapDrawable bm = new BitmapDrawable(bitmapScaled);

        return bm;



public class GroundOverlay extends Overlay {

Bitmap original;
Bitmap resized;
int lastZoomlevel;
SnowmapsOverlayObject snowmapsObject;
public static Boolean DRAW = false;
GeoPoint topGeoPoint;
GeoPoint bottomGeoPoint;

OnReady _onReady = null;

Boolean ready = false;

public GroundOverlay(Bitmap original, SnowmapsOverlayObject snowmapsObject) {
    this.original = Bitmap.createScaledBitmap(original, original.getWidth(), original.getHeight(), true);
    this.snowmapsObject = snowmapsObject;

    topGeoPoint = new GeoPoint((int) ((snowmapsObject.topLat).doubleValue() * 1E6), (int) ((snowmapsObject.topLng).doubleValue() * 1E6));
    bottomGeoPoint = new GeoPoint((int) ((snowmapsObject.bottomLat).doubleValue() * 1E6), (int) ((snowmapsObject.bottomLng).doubleValue() * 1E6));

public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, false);

        Projection projection = mapView.getProjection();

        Point leftTop = new Point();
        Point rightTop = new Point();
        Point rightBottom = new Point();
        Point leftBottom = new Point();

        projection.toPixels(topGeoPoint, leftTop);
        projection.toPixels(new GeoPoint(topGeoPoint.getLatitudeE6(), bottomGeoPoint.getLongitudeE6()), rightTop);
        projection.toPixels(bottomGeoPoint, rightBottom);
        projection.toPixels(new GeoPoint(bottomGeoPoint.getLatitudeE6(), topGeoPoint.getLongitudeE6()), leftBottom);

        if (
                (leftTop.x < 0 || leftTop.y < 0) && 
                (rightTop.x < 0 || rightTop.y < 0) && 
                (rightBottom.x < 0 || rightBottom.y < 0) && 
                (leftBottom.x < 0 || leftBottom.y < 0)) {
            // Not on screen? Don't draw the overlay

        //      GeoPoint mapCenter = mapView.getMapCenter();
        Paint paint = new Paint();

        canvas.drawBitmap(original, null, new Rect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y), paint);

        if (!ready && _onReady != null) {
            ready = true;

public boolean onTouchEvent(MotionEvent e, MapView mapView) {
    super.onTouchEvent(e, mapView);

    if (e.getAction() == MotionEvent.ACTION_UP) {

    return false;

private void setDrawTrue() {
    DRAW = true;
    new Handler().postDelayed(new Runnable() {

        public void run() {
            DRAW = false;
    }, 100);

public void setOnReady(OnReady onReady) {
    this._onReady = onReady;

public interface OnReady {
    public void done();

mixare (mix Augmented Reality Engine) is a free open source augmented reality browser, which is published under the GPLv3. mixare is available for Android and for the iPhone 3GS and above. It works as a completely autonomous application and is available as well for the development of own implementations.

Android Source-Code
iPhone Source-Code

We published in the Google Code wiki the instructions to put your own data in mixare!

mixare-App in the Android-Market:
mixare: available worldwide with data from wikipedia/geonames
Applications based on mixare in the Android-Market: available in Italy, Austria, Germany, Switzerland with data only (!) for South Tyrol (Italy) available in Italy, Austria, Germany, Switzerland with data only (!) for Trentino (Italy) available in Italy, Austria, Germany, Switzerland with data only (!) for Tyrol (Austria)