Show me the code! – By Davanum Srinivas

November 19, 2007

Drawing overlays for Android Maps (aka Search for Starbucks)

Filed under: Uncategorized — Davanum Srinivas @ 8:32 pm

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

28 Comments »

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

    Pingback by Working with Google Android’s Maps (aka Search for Pizza) « Show me the code! — November 19, 2007 @ 9:57 pm

  2. […] the original story for the code and Digg the story over at […]

    Pingback by Code Sample - Drawing overlays for Android Maps (aka Search for Starbucks) - Google Android Platform - The Android Log - Blog Archive — November 20, 2007 @ 1:36 pm

  3. […] 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, […]

    Pingback by » Twitter sur Android — November 21, 2007 @ 12:52 pm

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

    Comment by fabio — November 21, 2007 @ 5:37 pm

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

    Comment by frmad — November 23, 2007 @ 1:54 am

  6. 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.

    Comment by Lancelot — November 23, 2007 @ 6:57 am

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

    Comment by Gopinathan — November 25, 2007 @ 11:45 pm

  8. 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.

    Comment by Quauhtli Martinez — November 26, 2007 @ 10:12 pm

  9. 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))

    Comment by German Viscuso — November 28, 2007 @ 5:06 pm

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

    thanks,
    dims

    Comment by davanum — November 28, 2007 @ 8:32 pm

  11. 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.

    Comment by sudopeople — December 3, 2007 @ 2:31 pm

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

    Comment by Senthil Arjunan — December 5, 2007 @ 12:25 am

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

    Pingback by db4objects Releases Android Compatible db4o Database Product | Android Notes — December 6, 2007 @ 1:39 pm

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

    Pingback by db4o in Chinese : 使用db4o实现超强的Android地图应用 — December 13, 2007 @ 10:08 pm

  15. 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

    Comment by julian — December 29, 2007 @ 9:30 am

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

    Comment by srini — February 10, 2008 @ 10:24 pm

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

    Comment by srini — February 10, 2008 @ 10:25 pm

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

    Comment by Greg — March 10, 2008 @ 2:09 am

  19. 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!

    Comment by Titus — July 8, 2008 @ 8:45 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”

    Comment by Cassiano Tartari — August 24, 2008 @ 2:27 pm

  21. “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.

    Comment by Pat — November 3, 2008 @ 9:23 am

  22. 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

    Comment by Linh — January 12, 2009 @ 10:00 pm

  23. hello I am android beginner looking for pizza application in mapview.I need to developer pizza application which is given here it seems so good to learn the problem is import com.google.googlenav.Placemark;
    import com.google.googlenav.Search;

    these 2 package are not found in latest sdk
    plz mail me which android sdk does support these packages.

    Comment by saurabh — September 9, 2009 @ 5:07 am

  24. Great contribution!

    Neither the screenshots nor the source code is available at http://people.apache.org/~dims/android/ any more.

    I’d really appreciate if you can restore them, or someone post them somewhere else (keeping the original license and author credits).

    Thanks!

    Comment by Pablo — November 15, 2009 @ 8:14 am

  25. http://mirnauman.wordpress.com/2012/02/13/adding-image-to-googlemaps-using-map-overlays-android-tutorial-part-3/

    solves basic issues with using overlays. and gives a step by step way of adding images to google maps

    Comment by Mir — February 13, 2012 @ 3:55 am

  26. Reblogged this on Smartphone & E-Commerce and commented:
    Ví dụ hay về xử lý hiển thị mapbase Google API

    Comment by retailsmarter — March 4, 2012 @ 6:32 am

  27. explain this code ..what use of pixelcalculater & search…………….

    Comment by Mahivardhan Singh — September 14, 2012 @ 2:27 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: