http://davanum.wordpress.com/2007/11/30/android-poor-mans-my-location-show-current-cell-location/

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());
mPhoneStateReceiver.notifyServiceState(MY_NOTIFICATION_ID);
mPhoneStateReceiver.notifyPhoneCallState(MY_NOTIFICATION_ID);
mPhoneStateReceiver.notifySignalStrength(MY_NOTIFICATION_ID);
mPhoneStateReceiver.registerIntent();

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;
                        updateTextFields();
                    }
                    break;
            }
        }
    }

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

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:
002

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 APIfrom Yahoo. So we construct a nice URL with the information entered on screen.
http://zonetag.research.yahooapis.com/services/rest/V1/cellLookup.php?apptoken=ZoneTagDemoToken&cellid=20442&lac=6015&mnc=410&mcc=310

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. 
http://local.yahooapis.com/MapsService/V1/geocode?appid=YahooDemo&city=Boston&state=Massachusetts&zip=02215

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);
startActivity(intent);

003

Piece of cake :)

Download The Sources And Application – LocateMe-2.0.Zip

+ Recent posts