Show me the code! – By Davanum Srinivas

Web Services, Apache, Websphere, IBM, etc.

Drawing overlays for Android Maps (aka Search for Starbucks)

with 23 comments

Without much Ado – Here are the screen shots

001
002
003

Key strokes

  • S – Toggle satellite imagery
  • T – Toggle traffic imagery
  • I – Zoom in
  • O – Zoom out
  • F – Search for addresses or businesses
  • P – Search for pizza :)
  • 1 / 2 / 3 …. 9 – Display information about a specific item and center it

Code sample for Overlays

package org.apache.maps;

import android.graphics.Canvas;
import android.graphics.Paint;
import com.google.android.maps.Overlay;
import com.google.android.maps.Point;
import com.google.googlenav.Placemark;
import com.google.googlenav.Search;

public class MyOverlay extends Overlay {
    BrowseMap mMap;
    Paint paint1 = new Paint();
    Paint paint2 = new Paint();

    public MyOverlay(BrowseMap map) {
        mMap = map;
        paint2.setARGB(255, 255, 255, 255);
    }

    public void draw(Canvas canvas, PixelCalculator pixelCalculator, boolean b) {
        super.draw(canvas, pixelCalculator, b);

        Search search = mMap.getSearch();
        if (search != null) {
            for (int i = 0; i < search.numPlacemarks(); i++) {
                Placemark placemark = search.getPlacemark(i);
                int[] screenCoords = new int[2];
                Point point = new Point(placemark.getLocation().getLatitude(),
                        placemark.getLocation().getLongitude());
                pixelCalculator.getPointXY(point, screenCoords);
                canvas.drawCircle(screenCoords[0], screenCoords[1], 9, paint1);
                canvas.drawText(Integer.toString(i + 1),
                        screenCoords[0] - 4,
                        screenCoords[1] + 4, paint2);
            }
        }
    }
}

Download the sources and Application – BrowseMap2.0.zip

Written by Davanum Srinivas

November 19, 2007 at 8:32 pm

Posted in Uncategorized

23 Responses

Subscribe to comments with RSS.

  1. [...] UPDATE (Nov 19, 2007): Please see here for Version 2.0 Drawing overlays for Android Maps (aka Search for Starbucks) [...]

  2. [...] est disponible sur Show Me The Code, un très bon site au passage !! Sur le même site, une autre application est disponible, utilisant l’API Google Maps. Cet article à été publié le Mercredi, [...]

    » Twitter sur Android

    November 21, 2007 at 12:52 pm

  3. Hi! Why does your application does not close on the press of the “return button” ? How to fix it?

    fabio

    November 21, 2007 at 5:37 pm

  4. Congratulation! Your weblog’s high ranked in “The professional WordPress weblog ranking” at http://weblogrank.edu.ms

    frmad

    November 23, 2007 at 1:54 am

  5. Hello:

    Thanks for the application, it´s really nice.

    I have a question that I haven´t been able to answer it. Why the searth just finds 9 locations??. I don´t get it, what do i have to do to make search for more??.

    thanks and sorry for my english.

    Lancelot

    November 23, 2007 at 6:57 am

  6. Nice application.I tried your code,Its working fine but its not marking the location. Can u help me to sort this problem.

    Gopinathan

    November 25, 2007 at 11:45 pm

  7. It is possible to interact with those points? I mean, for example, instead locating Starbuck’s, you want to locate your friends so when you find them you can click on one of them and automatically calls it.

    Quauhtli Martinez

    November 26, 2007 at 10:12 pm

  8. Hi! This is excellent!! Thx!!
    What is the license for the code? (Can we use it on other open source apps for Android? (e.g. with Apache licensed Android apps))

    German Viscuso

    November 28, 2007 at 5:06 pm

  9. German,
    All the code on this web site written by me is under Apache License 2.0 (http://www.apache.org/licenses/).

    thanks,
    dims

    davanum

    November 28, 2007 at 8:32 pm

  10. For everyone’s information including the author’s:

    paint1.setAntiAlias(true);

    will really make those black circles look nice!

    @davanum,
    do you know how to draw images on the overlay in place of those circles?

    I’ve looked into:

    android.graphics.BitmapFactory.decodeResource();

    but I have no idea what to pass as arguments.

    I tried Bitmap icon = android.graphics.BitmapFactory.decodeResource(R.drawable.home);

    to no avail.

    sudopeople

    December 3, 2007 at 2:31 pm

  11. Hi..very nice..thanks!!this is very helpful..

    Senthil Arjunan

    December 5, 2007 at 12:25 am

  12. [...] originally written by Steve Osborne and available here. Also, MapMe, based on original code for BrowseMap by and first written about at AndroidNotes [...]

  13. [...] Viscuso    译者:Rosen简介 本项目基于Davanum Srinivas开发的BrowseMap,BrowseMap是一个为Android开发的Google [...]

  14. Ya he leido el foro y la verdad mi computador hace pate de una red interna por ello necesita un proxy y me gustaria mucho saber si alguien sabe configurarlo en el android para que la aplicacion maps funciones

    julian

    December 29, 2007 at 9:30 am

  15. how can i use latitude and logitue to search the map and what api’s i have to use Android SDK

    srini

    February 10, 2008 at 10:24 pm

  16. How to use andoroid api to search directions on google maps

    srini

    February 10, 2008 at 10:25 pm

  17. How can we get POI (point of intrests) of all the restorants in US???

    Greg

    March 10, 2008 at 2:09 am

  18. Hello! I am brand new to Android and this may seem like a simple question but how do i get the app into Eclipse? I have tried import but I can’t seem to get it…any ideas?
    Thanks so much for the amazing resource!

    Titus

    July 8, 2008 at 8:45 pm

  19. Someone could send me the file BrowseMap2.0.zip because when I try to download it, redirect me to a page “Not Found”

    Cassiano Tartari

    August 24, 2008 at 2:27 pm

  20. “Someone could send me the file BrowseMap2.0.zip because when I try to download it, redirect me to a page “Not Found””

    Me tool.

    Pat

    November 3, 2008 at 9:23 am

  21. hi,
    Thank you very much for your excellent blogs on Android, I’ve learn a lot from these.
    BTW, I am a newbie in Android programming and playing with Google maps, Could you please give me the link to download the source code of this post ?
    Or send me the code if any,

    Thank you very much in advance
    Best Regards

    Linh

    January 12, 2009 at 10:00 pm


Leave a Reply