Search code examples
androidwificelllocationmanager

How do you make Android LocationManager use Cell network and not Wifi network?


I have an android application using LocationManager get the cell network location and not the Wifi location? If I have turned off the Wifi antenna and do the following:

LocationManager lm = (LocationManager) paramContext.getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

I am always returned the Wifi location and not the cell network location. I want it to return the cell location since I have moved fromthe Wifi location. I tried using a LocationListener but that doesn't seem to help.

This is running on an HTC Evo running Froyo.

Thanks!


Solution

  • I don't believe you can.

    Network location provider look at the wifi state and cell state, discard one if too old, or send them both over to the Google Location Server (GLS) via MASF server. What's done there is magic. But you can look at the implementation of NetworkProvider and see how to tweak your code. Codes are here: NetworkLocationProvider.

    If you just want the cell ID, check out Telephony Manager. Add a PhoneStateListener there.