aandroidtest
aandroidtest

Reputation: 1503

Retrieving Device Location using Location API vs Telephony API

What's the difference between getting the location using the Location API vs the Telephony API?

Previously, I have asked a question on getting the location when location services are not enabled. See: Retrieving GPS coordinates when location services are not enabled

Apparently, using the telephone API, http://developer.android.com/reference/android/telephony/CellLocation.html this is possible. This returns a integer which I think is the Base Station ID?

Am I correct? What's the difference?

Upvotes: 0

Views: 761

Answers (3)

Abhay Kumar
Abhay Kumar

Reputation: 1618

Location Api will use gps, agps or glonass to retrieve location but in telephony api the location give is not as precise as a gps location because the location is returned by the carrier (mobile operator). Telephony api calculates location using triangulation.

Upvotes: 0

Misha Bhardwaj
Misha Bhardwaj

Reputation: 1387

The basic difference in getting location from Location API or Telephony API lies in method of getting location.

Location API returns location based on your GPS network. Your Android device requests its distance from satellites in the GPS network and plots the intersection points along the boundary of the described spheres while Telephony API locates you based on your cell id(the integer you are getting in response to getCellLocation()). You probably already know that your phone is virtually always connected to the nearest cell tower. Each cell tower’s exact location is known by its operators and is assigned to the tower as a Cell ID within a Location Area Code (LAC). Your phone stores the Cell ID and LAC of every tower to which you connect, giving it a rough idea of your location.

For more information, you can visit this link.

Upvotes: 4

Joshua D. Boyd
Joshua D. Boyd

Reputation: 4856

CellLocation is an abstract base class that doesn't provide any sort of get location methods. Instead, you have to use CdmaCellLocation or GsmCellLocation.

CdmaCellLocation offers getBaseStationId, which is what you presumably referred to as something returning an int for the base station id. CdmaCellLocation also offers getBaseStationLatitude and getBaseStationLongitude, which should be exactly what you want when on a CDMA device. However, GsmCellLocation does not offer such methods. You would need to use the CID and LAC and a service like openbmap or opencellid to convert CID/LAC to latitude and longitude.

So, in short, the Location API gives you the location in a straight-forward manor. The Telephony API gives you information about the cell connection (if present) and you have to provide separate implementations for both GSM and CDMA, and if the device has GPS but no telephony you've screwed the user. Also, I would like to point out a reply you previously got: https://stackoverflow.com/a/13491028/198480

Upvotes: 1

Related Questions