Skip to content

Commit 6766276

Browse files
barbeauJean-Baptiste Queru
authored andcommitted
Adds utility method to convert 0.25 secs to decimal degrees
This patch adds a utility method that converts latitude and longitude in quarter seconds units to decimal degrees units. The Telephony API returns CDMA base station latitude and longitude in quarter seconds due to a 3GPP telecom standard, while the Android Location API, and the vast majority of application-level code, uses decimal degrees. For example, to measure the distance from the user's current location to the base station using the Location API Location.distanceBetween() method (http://goo.gl/YjO8O), the base station lat and long would need to be converted to decimal degrees first. Since most application developers will likely never use lat/long information in quarter seconds units, and instead will need this information in decimal degrees, this utility method will frequently be used by anyone querying base station location data from CdmaCellLocation. Sample values to test conversion: 0.25 seconds: lat = 399491, long = -1189145 is equivalent to decimal degrees: lat = 27.742430555555554, long = -82.57951388888888 Change-Id: If03e741f5035a37519f50d4fb2fb3e3eef2505da Signed-off-by: Sean Barbeau <sjbarbeau@gmail.com>
1 parent 1b34c1b commit 6766276

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19290,6 +19290,7 @@ package android.telephony.cdma {
1929019290
public class CdmaCellLocation extends android.telephony.CellLocation {
1929119291
ctor public CdmaCellLocation();
1929219292
ctor public CdmaCellLocation(android.os.Bundle);
19293+
method public static double convertQuartSecToDecDegrees(int);
1929319294
method public void fillInNotifierBundle(android.os.Bundle);
1929419295
method public int getBaseStationId();
1929519296
method public int getBaseStationLatitude();

telephony/java/android/telephony/cdma/CdmaCellLocation.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,22 @@ public boolean isEmpty() {
215215
this.mNetworkId == -1);
216216
}
217217

218+
/**
219+
* Converts latitude or longitude from 0.25 seconds (as defined in the
220+
* 3GPP2 C.S0005-A v6.0 standard) to decimal degrees
221+
*
222+
* @param quartSec latitude or longitude in 0.25 seconds units
223+
* @return latitude or longitude in decimal degrees units
224+
* @throws IllegalArgumentException if value is less than -2592000,
225+
* greater than 2592000, or is not a number.
226+
*/
227+
public static double convertQuartSecToDecDegrees(int quartSec) {
228+
if(Double.isNaN(quartSec) || quartSec < -2592000 || quartSec > 2592000){
229+
// Invalid value
230+
throw new IllegalArgumentException("Invalid coordiante value:" + quartSec);
231+
}
232+
return ((double)quartSec) / (3600 * 4);
233+
}
218234

219235
}
220236

0 commit comments

Comments
 (0)