Show me the code! – By Davanum Srinivas

November 15, 2007

Working with Google Android’s Maps (aka Search for Pizza)

Filed under: Uncategorized — Davanum Srinivas @ 12:14 pm

Here’s some sample code to zoom in/out, switch on traffic/satellite images. Note that the MapView stuff is not fleshed out yet!! Hence lots of undocumented stuff that is likely to change.

package org.apache.maps;

import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

public class BrowseMap extends MapActivity {
    private MapView mMapView;

    private String LOG_TAG = "BrowseMap";

    public void onCreate(Bundle icicle) {
        mMapView = new MapView(this);

        // Use Yahoo Geo code to find the lat/long.
        // Click on the Sample Request URL here for example
        Point p = new Point((int) (37.416402 * 1000000), (int)
                (-122.025078 * 1000000));
        MapController mc = mMapView.getController();

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_I) {
            // Zoom In
            int level = mMapView.getZoomLevel();
            mMapView.getController().zoomTo(level + 1);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_O) {
            // Zoom Out
            int level = mMapView.getZoomLevel();
            mMapView.getController().zoomTo(level - 1);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_S) {
            // Switch on the satellite images
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_T) {
            // Switch on traffic overlays
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_P) {
            // W00t! Search for Pizza.
            // Create a MapPoint from the map's coordinates
            MapPoint mapPoint = new MapPoint(mMapView.getMapCenter().getLatitudeE6(),
            // Create a dummy Map for use in Search
            Map map = new Map(getDispatcher(), null, 0, 0, 0, mapPoint,
                    Zoom.getZoom(mMapView.getZoomLevel()), 0);
            // Search for Pizza near the specified coordinates
            Search search = new Search("Pizza", map, 0);
            // add the request the dispatcher
            // Wait for the search to complete, Should do this
            // in another thread ideally, this is just for illustration here.
            while (!search.isComplete()) {
                Log.i(LOG_TAG, ".");

            // Print the details.
            Log.i(LOG_TAG, "Done - " + search.numPlacemarks());
            MapPoint point = null;
            for (int i = 0; i < search.numPlacemarks(); i++) {
                Placemark placemark = search.getPlacemark(i);
                point = placemark.getLocation();
                Log.i(LOG_TAG, " - i : " + Integer.toString(i));
                Log.i(LOG_TAG, "- Bubble : " + placemark.getBubbleDescriptor());
                Log.i(LOG_TAG, "- Detail : " + placemark.getDetailsDescriptor());
                Log.i(LOG_TAG, "- Title : " + placemark.getTitle());
                Log.i(LOG_TAG, "- Location : " + placemark.getLocation().toString());
                Log.i(LOG_TAG, "- routable : " + placemark.routableString());

            // Animate to the last location.
            if (point != null) {
                MapController mc = mMapView.getController();
                Point point1 = new Point(point.getLatitude(), point.getLongitude());
                Log.i("animateTo", point1.toString());
            return true;
        return false;

Here’s the complete zip

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


  1. […] [working-with-google-androids-maps-aka-search-for-pizza]-Working with Google Android’s Maps FYI, [link] […]

    Pingback by [working-with-google-androids-maps-aka-search-for-pizza]-Working with Google Android’s Maps « Malnews3’s Weblog — November 16, 2007 @ 3:17 am

  2. […] have already made sample applications. This is a good thing because early adopters make the current buzz even stronger. Now, if these […]

    Pingback by that’s great… » android says, “hello world”… — November 16, 2007 @ 11:20 am

  3. Good work! Just curious, where did you get the api doc for*? I couldnt find the javadoc on


    Comment by raja — November 20, 2007 @ 11:39 am

  4. […] (Cet exemple ci montre comment trouver des pizza avec un GPhone 😉 ) […]

    Pingback by Helyx Weblog » Blog Archive » Première contributions et démos intéressantes pour Android — November 21, 2007 @ 4:15 pm

  5. […] the weekend, he released his BrowseMap 2.0 sample code for using Overlay to draw Starbucks locations onto a map, as an update to his earlier BrowseMap […]

    Pingback by Tutorials: TwitterClient and BrowseMap 2.0 | Android Notes — November 23, 2007 @ 12:38 pm

  6. Hi, I am from Kanpur, i am behind the proxy and it will ask authentication. My port number is: 3128.

    Why am tell all these things is , I can’t open map application which is given by emulator itself.
    I have read one article in Google group; it says that, In India Map application will not open without proxy tunnel and proxifire. Is it true?
    I set Http Proxy settings using following sqlite3 Command,
    adb shell sqlite3 /data/data/ “\” insert into system values(99,’http_proxy’,’’);\””

    I set User Name and password using following command,
    adb shell sqlite3 /data/data/ “\” insert into password values(99,’username’,’passwords’);\””

    Can you help me solve this problem?

    Venkat. 🙂

    Comment by Venkat — December 28, 2007 @ 1:50 pm

  7. Do you know how to incorporate driving directions into your program? If so, can you tell me how?

    Thanx a million,

    Comment by Tarek — December 30, 2007 @ 5:32 pm

  8. Search snippet shown in this sample only returns 9 results. How do I get results updated for 2nd set of 9 results? (i.e. beyond the 1st 9 results returned.)
    I still can’t find any documentation on* 😦

    Comment by Jay Kim — January 16, 2008 @ 2:23 am

  9. Davanum,

    I wonder if this has been changed in latest SDK? or Android team is trying to prevent such actions.

    I’ve got the latest SDK from dec 14th. and whenever i create a dummy map for the search, it always has inside MapPoint set to (36.149777,-95.993398), without considering the point that i pass in. I’ve tried your coordinates, palo alto… doesn’t work, the default map is always created with the above location.

    Has anyone got it working?

    Comment by Alexey — January 25, 2008 @ 2:56 am

  10. Hi,
    its vey useful code give by you.
    Could please provide me the API reference for as i did not find it.

    Thanks in advance

    Comment by kishor — February 4, 2008 @ 6:45 am

  11. Placemark is not present in

    Comment by rahul — March 9, 2008 @ 12:54 pm

  12. Hi guys,

    I could not find “”.

    Can anyone please tell me where I can find googlenav.Search


    Comment by Chris Sammut — April 13, 2008 @ 5:57 am

  13. Hi,

    Thanks a lot for the wonderful and useful information. I was trying to access the zip file but could not download the same from the site. Could you please provide me the same.


    Comment by Sidhartha — September 16, 2008 @ 12:49 am

  14. I am finding some problems in compiling the code. What version of android SDK to be used??

    Comment by Ellen — November 1, 2008 @ 11:04 pm

  15. The link to download the zip file is not working. Can anyone please send it to me at sagar AT gatech DOT edu


    Comment by Sag — November 29, 2008 @ 5:57 pm

  16. […] Working with Google Android’s Maps (aka Search for Pizza) « Show me the code! […]

    Pingback by Android Developer Resources, useful links « Eulogik — July 24, 2009 @ 4:46 am

  17. It maybe a little too late, but still helpful for others.
    I have written a few simple classes to get and display driving directions in MapView for Android:

    Hope it helps!


    Comment by Andrea — December 2, 2009 @ 12:13 pm

  18. how to get API google doc ? its very confuse operating it without the doc

    Comment by atics — June 13, 2010 @ 9:35 am

  19. I’m new to android apps development,

    I want to show more than one markers in the map, how do i get lan and lon value for displaying more than one one markers.

    My apps is similar to friend finder. Could you suggest any ideas or link for the coding

    thanks in advance,

    Comment by Kumar — November 9, 2010 @ 5:33 am

  20. Hi

    This tutorial is very helpful for me to develop the map application for android

    Thank you

    Comment by Krishna — November 9, 2010 @ 11:51 am

  21. i can’t download source your aplication…
    i want read this full source…
    for my thesis

    Comment by Java Android UPN Community — November 2, 2011 @ 2:18 pm

  22. how can i place pinpoint in google map by giving latitude and longitude???

    Comment by saran — January 26, 2012 @ 1:54 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: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

Blog at

%d bloggers like this: