1

I'm developing an android app for CDMA phones that will gather the latitude/longitude of the cell tower they are connected to.

First: is this even possible?

Second: I've looked at previous posts where it says to simply add "CellLocation.requestLocationUpdate();" but it didn't have any effect. Here's the portion of code where I'm trying to retrieve the locations...

CdmaCellLocation CdmaLocation = (CdmaCellLocation)telephonyManager.getCellLocation();
int Longitude = CdmaLocation.getBaseStationLongitude();
int Latitude = CdmaLocation.getBaseStationLatitude();

Looking at the code for the CdmaCellLocation class reveals that those values are defaulted to Integer.MAX_VALUE, but how do you actually set the latitude and longitude?

Community
  • 1
  • 1
miriye
  • 143
  • 5
  • Before you cast `getCellLocation` to `CdmaCellLocation`, check your phoneType with `telephonyManager.getPhoneType()`, only cast it to Cdma if `telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA`. If you get `TelephonyManager.PHONE_TYPE_GSM` you should cast it to `GsmCellLocation`. I believe you get weird integer because the phone type is not cdma. – Chor Wai Chun May 20 '13 at 01:30
  • I just tried adding that to the code and unfortunately it didn't solve the problem. I probably should have mentioned that I'm already testing on a CDMA phone. Thanks for the quick response though – miriye May 23 '13 at 18:54

1 Answers1

1

you have to use PhoneStateListener with LISTEN_CELL_LOCATION and the corresponding callback function onCellLocationChanged(CellLocation) and LISTEN_CELL_INFO with callback function onCellInfoChanged(List) and possibly LISTEN_SIGNAL_STRENGHTS with callback onSignalStrengthsChanged(Signal Strength)

to quit getting change notification from the PhoneStateListener use LISTEN_NONE

http://www.truiton.com/2014/08/android-phonestatelistener-example/

https://developer.android.com/reference/android/telephony/PhoneStateListener.html

ralf htp
  • 9,149
  • 4
  • 22
  • 34