From 67662767d98c42c34519767956aebe9d90f31c3a Mon Sep 17 00:00:00 2001 From: Sean Barbeau Date: Thu, 12 Jan 2012 23:37:47 -0500 Subject: 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 --- .../java/android/telephony/cdma/CdmaCellLocation.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'telephony/java/android') diff --git a/telephony/java/android/telephony/cdma/CdmaCellLocation.java b/telephony/java/android/telephony/cdma/CdmaCellLocation.java index 84db830..4fea793 100644 --- a/telephony/java/android/telephony/cdma/CdmaCellLocation.java +++ b/telephony/java/android/telephony/cdma/CdmaCellLocation.java @@ -215,6 +215,22 @@ public class CdmaCellLocation extends CellLocation { this.mNetworkId == -1); } + /** + * Converts latitude or longitude from 0.25 seconds (as defined in the + * 3GPP2 C.S0005-A v6.0 standard) to decimal degrees + * + * @param quartSec latitude or longitude in 0.25 seconds units + * @return latitude or longitude in decimal degrees units + * @throws IllegalArgumentException if value is less than -2592000, + * greater than 2592000, or is not a number. + */ + public static double convertQuartSecToDecDegrees(int quartSec) { + if(Double.isNaN(quartSec) || quartSec < -2592000 || quartSec > 2592000){ + // Invalid value + throw new IllegalArgumentException("Invalid coordiante value:" + quartSec); + } + return ((double)quartSec) / (3600 * 4); + } } -- cgit v1.1