I am calculating distance from latitude and longitude in sqlite in android. First I have to fetch coordinates from web service then I have to converted coordinates from degrees to radians using below code:
Math.cos(deg2rad(outlet.getLatitude()))
Math.sin(deg2rad(outlet.getLatitude()))
public static double deg2rad(double deg) {
return (deg * Math.PI / 180.0);
}
then I have inserted it into my Table and then I am using this query to calculate the distance in sqlite. When I run this query:
SELECT "location",
(sin_lat_rad "sin_lat_rad" + cos_lat_rad "cos_lat_rad" *
(sin_lon_rad "sin_lon_rad" + cos_lon_rad "cos_lon_rad"))