Show me the code! – By Davanum Srinivas

November 30, 2007

Android – Poor man’s “My Location” (Show current cell location)

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

Many Thanks to Nicholas and bloid for comments on my previous blog post. Here’s an update with some commentary

Step #1: Get the Cell-Id, LAC, MCC and MNC from the cell phone

Set up a PhoneIntentReceiver as shown below:

// Set up the handler for receiving events for service state etc.
mPhoneStateReceiver = new PhoneStateIntentReceiver(this, new ServiceStateHandler());

And the handler snippet is below. Note that he MNC/MCC information is returned by the getOperatorNumeric method.

     * Notification Handler for Phone events
    private class ServiceStateHandler extends Handler {
        private boolean updateOnce = false;

        public void handleMessage(Message msg) {
            Log.i("LocateMe", "In handleMessage : " + msg.what);
            switch (msg.what) {
                case MY_NOTIFICATION_ID:
                    ServiceState state = mPhoneStateReceiver.getServiceState();
                    notification_cid = state.getCid();
                    notification_lac = state.getLac();
                    notification_signal = mPhoneStateReceiver.getSignalStrength();
                    notifiction_operator_numeric = "" + state.getOperatorNumeric();

                    if (updateOnce == false) {
                        updateOnce = true;

Here’s a screen shot with the default values that you get from the emulator:

Since the default information from emulator is unusable, let’s find something we can use say from this site –
“groovy mother…”
Here’s a screen shot:

Step #2: Convert the Cell information into an Address

Now the question is how do we get an address information from the cellid/lac/mnc/mcc. The GNUCITIZEN site has a nice tip on how to use the ZoneTag API from Yahoo. So we construct a nice URL with the information entered on screen.

Just Click on the URL above to see the XML that it returns.

Step #3: Convert Address into a Lat/Long

Just use the Yahoo GeoCode API. We parse the XML from the previous step, extract the city, state, zip and construct a new URL.

Again just Click on the URL above to see the XML that it returns.

Step #4: Launch the Maps

ContentURI uri = ContentURI.create("geo:" + myContentHandler2.getLatitude()
     + "," + myContentHandler2.getLongitude());
Intent intent = new Intent("android.intent.action.VIEW", uri);


Piece of cake 🙂

Download the sources and Application –

UPDATE: December 1, 2007 8 AM EST – Latest version is here


  1. […] UPDATE: Nov 30, 12:37 EST – Version 2.0 is here […]

    Pingback by Android - Access Cell Phone details (Cell-Id, LAC, Signal Strength) « Show me the code! — November 30, 2007 @ 12:38 pm

  2. Hi
    I succeed to compile it but I did’t found how to run it…

    I try to put it under Eclipse but import failed.

    I am working under linux.

    Any help welcome.
    Your appli looks very nice and I would like to run it.


    Comment by Andre — December 1, 2007 @ 11:33 am

  3. When I run the app the just click on the “Locate Me!” button, I get an error message telling “Application error: An error has occured in process Unable to start activity […..]”. Any ideas ?

    Comment by l3v1 — January 3, 2008 @ 5:04 am

  4. […] Then I build the XML SAX parsing part by referenced from Davanum Srinivas’ LocateMe at: […]

    Pingback by Mobile Application Code Shogun » Blog Archive » Android GoogleMaps Mini — March 7, 2008 @ 11:43 pm

  5. you can send the locateme for my email?? your link is broken.


    Comment by lucio flavio — October 30, 2009 @ 10:40 am

  6. can you send me the source code? your link is broken


    Comment by boudi — March 24, 2010 @ 3:47 am

  7. can you send me the source code? your link is broken
    thank you

    Comment by wangpeng — May 20, 2010 @ 4:23 am

  8. could you send me the source code?

    Comment by lance — August 23, 2010 @ 7:53 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

Create a free website or blog at

%d bloggers like this: