Java tutorial
//package com.java2s; //License from project: Open Source License import android.location.Location; import android.util.Log; public class Main { /** * * @param lat1 * @param lng1 * @param lat2 * @param lng2 * @return distance in km */ public static float distFrom(double lat1, double lng1, double lat2, double lng2) { Log.e("lat1" + lat1 + " long1" + lng1, "lat 2" + lat2 + " long2" + lng2); /*double earthRadius = 6371; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double sindLat = Math.sin(dLat / 2); double sindLng = Math.sin(dLng / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; Log.e("difference in distance",""+dist); return distance(lat1, lng1, lat2, lng2);*/ float[] result = new float[3]; Location.distanceBetween(lat1, lng1, lat2, lng2, result); //conversion to m result[0] = result[0] / 1000; return result[0]; } }