Android Utililty Methods Distance Calculate

List of utility methods to do Distance Calculate

Description

The list of methods to do Distance Calculate are organized into topic(s).

Method

 double getDistance(double lat1, double lon1, double lat2, double lon2)get Distance ```float[] results = new float[1]; Location.distanceBetween(lat1, lon1, lat2, lon2, results); return results[0]; ``` float dist(PointF p1, PointF p2)dist ```float dist = (float) Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2)); return dist; ``` int distance(int q1, int r1, int q2, int r2)distance ```return (Math.abs(q1 - q2) + Math.abs(r1 - r2) + Math.abs(q1 + r1 - q2 - r2)) / 2; ``` double distanceBetweenTwoLatLongs(Location oldLocation, Location newLocation)distance Between Two Lat Longs ```double distance = 0; if (newLocation != null && oldLocation != null) { distance = oldLocation.distanceTo(newLocation); } else { if (newLocation == null) { Log.e("newLocation is null", ";;"); if (oldLocation == null) { ... ``` String distanceInMeters(float distance)distance In Meters ```String distanceStr = ""; if (distance > 0) { if (distance >= 1000) { distanceStr = " " + Float.toString(distance / 1000).replace(".", ",") + " km"; } else { if (distance % 1 == 0) { ... ``` double distanceBetweenTwoPoints(double lat1, double lng1, double lat2, double lng2)distance Between Two Points ```int r = 6371; double dLat = Math.toRadians(lat2 - lat1); double dLon = 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(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); ... ``` int KmToMiles(int distance)Km To Miles ```double dist = distance * 0.621; return (int) dist; ``` int getTempsTrajetBus(int distance)get Temps Trajet Bus ```double coef = 1.4; return (int) ((distance * coef) / 11.1); ``` int getTempsTrajetPied(int distance)get Temps Trajet Pied ```double coef = 1.4; return (int) ((distance * coef) / 1.38); ``` int hammingDistance(String sourceHashCode, String hashCode)hamming Distance ```int difference = 0; int len = sourceHashCode.length(); for (int i = 0; i < len; i++) { if (sourceHashCode.charAt(i) != hashCode.charAt(i)) { difference++; return difference; ... ```