I am writing a location-based application and I want to get some wisdom regarding the reasonable use of the API.
What I have understood so far is that working with int is more efficient. I will need to store loads and do a lot of estimated distances.
My application uses a Service that implements a LocationListener, and I store the longitude and latitude as int (micro-degrees) values inside SQL db (via ormlite), calculated this way:
public static int degreesToMicroDegrees(double degrees){
return (int)(degrees * 1E6);
}
Sometimes I need to know when I get back to a specific “location,” and as such I retrieve the int values from db for comparison with the last update to the location.
Question: what is the best way to compare the “location” between int values (where I was before) and double values (where I am now) in the last location update?
I searched around some Math to calculate the distance and found this ::
public static double distanceBetween(double lat1, double lng1, double lat2, double lng2) {
double earthRadius = 3958.75;
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;
return dist;
}
I tried passing my int values as follows: ((double) myIntValue) / 1E6F The returned distance values confuse me. If I go 100 meters, my application with feeling tells me that I worked about 100 meters using Location.distanceTo (myLastLocation). But if I use a method higher than my stored int values, I get a null value.
If someone could explain the E6 format, that would be great.
Is 1E6 the same as 1,000,000?
, , GeoPoint. , , GeoPoints Google. , API GoogleMaps, , .
.