13

Does anyone know if it is possible to get information about all of the cell towers in range of a device? Just be able to get the location of them or maybe any other information about them and how I would go about doing it?

DRiFTy
  • 11,269
  • 11
  • 61
  • 77
  • Take a look here. This is almost the same question. http://stackoverflow.com/questions/5184877/how-to-find-user-location-using-cell-tower-in-android – AlexR Jul 12 '11 at 17:23
  • Thanks I must've overlooked that when reading the API. I will give it a try. – DRiFTy Jul 12 '11 at 17:26
  • One additional resource: http://www.anddev.org/poor_mans_gps_-_celltowerid_-_location_area_code_-lookup-t257.html – AlexR Jul 12 '11 at 17:27
  • 2
    I thought he wanted the actual locations of the cell towers, not his location based on cell towers... – citizen conn Jul 12 '11 at 17:35

1 Answers1

10

This is how you get the cell tower id (CID) and the lac (Location Area Code) from your current network state:

mPhoneStateReceiver = new PhoneStateIntentReceiver(this, new ServiceStateHandler());
mPhoneStateReceiver.notifyServiceState(MY_NOTIFICATION_ID);
mPhoneStateReceiver.notifyPhoneCallState(MY_NOTIFICATION_ID);
mPhoneStateReceiver.notifySignalStrength(MY_NOTIFICATION_ID);
mPhoneStateReceiver.registerIntent();

private class ServiceStateHandler extends Handler {
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MY_NOTIFICATION_ID:
                ServiceState state = mPhoneStateReceiver.getServiceState();
                System.out.println(state.getCid());
                System.out.println(state.getLac());
                System.out.println(mPhoneStateReceiver.getSignalStrength());
                break;
        }
    }
}

Getting Lat,Lng location information after that is a little trickier. Here's a link to a post that's about Symbian but talks about Cell Tower -> Lat,Lng conversion: http://discussion.forum.nokia.com/forum/showthread.php?s=&threadid=19693

citizen conn
  • 15,300
  • 3
  • 58
  • 80
  • If I'm not mistaken, PhoneStateIntentReceiver is not a visible class. What is its import? On which API level does this code work? – Paul Lammertsma Jul 12 '11 at 18:08
  • 2
    Interesting, I dug this one up from an old app and now its non-existent. This appears to be the new replacement: [PhoneStateListener](http://developer.android.com/reference/android/telephony/PhoneStateListener.html) – citizen conn Jul 12 '11 at 18:25
  • Hi I want to get cell tower location , but i am not able to get that location. Could you please tell me how to get cell tower location...? – Dipali Mar 07 '12 at 07:06
  • 1
    Actually, the new API is apparently [CellIdentityGsm](http://developer.android.com/reference/android/telephony/CellIdentityGsm.html): it has methods `getCid()` and `getLac()`. – sleske Mar 25 '13 at 13:56
  • @sleske : Just for shortcut information. It's for API 17 (Android 4.2 Jelly Bean) and above – poring91 Feb 21 '17 at 05:53