private LatLng getPoint(LatLng center, int radius, double angle) { // Get the coordinates of a circle point at the given angle double east = radius * Math.cos(angle); double north = radius * Math.sin(angle); double cLat = center.latitude; double cLng = center.longitude; double latRadius = earthRadius * Math.cos(cLat / 180 * Math.PI); double newLat = cLat + (north / earthRadius / Math.PI * 180); double newLng = cLng + (east / latRadius / Math.PI * 180); Log.v("New Lat", newLat + ""); Log.v("New Lat", newLng + ""); return new LatLng(newLat, newLng); }public static float calculateDistance(float lat1, float lon1, float lat2, float lon2) { float dLat = (float) Math.toRadians(lat2 - lat1); float dLon = (float) Math.toRadians(lon2 - lon1); float a = (float) (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)); float c = (float) (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))); float d = (float) (earthRadius * c); return d; } public static double distanceCalcByHaversine(GeoPoint startP, GeoPoint endP) { double lat1 = startP.getLatitudeE6() / 1E6; double lat2 = endP.getLatitudeE6() / 1E6; double lon1 = startP.getLongitudeE6() / 1E6; double lon2 = endP.getLongitudeE6() / 1E6; double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); 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)); return earthRadius * c; } public static double distanceKm(double lat1, double lon1, double lat2, double lon2) { Log.d("slatitute", " " + lat1); Log.d("slongi", " " + lon1); Log.d("tlatitute", " " + lat2); Log.d("tlongi", " " + lon2); int EARTH_RADIUS_KM = 6371; double lat1Rad = Math.toRadians(lat1); double lat2Rad = Math.toRadians(lat2); double deltaLonRad = Math.toRadians(lon2 - lon1); return Math .acos(Math.sin(lat1Rad) * Math.sin(lat2Rad) + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad)) * EARTH_RADIUS_KM; }
private LatLng getPoint(LatLng center, int radius, double angle) {
ReplyDelete// Get the coordinates of a circle point at the given angle
double east = radius * Math.cos(angle);
double north = radius * Math.sin(angle);
double cLat = center.latitude;
double cLng = center.longitude;
double latRadius = earthRadius * Math.cos(cLat / 180 * Math.PI);
double newLat = cLat + (north / earthRadius / Math.PI * 180);
double newLng = cLng + (east / latRadius / Math.PI * 180);
Log.v("New Lat", newLat + "");
Log.v("New Lat", newLng + "");
return new LatLng(newLat, newLng);
}
public static float calculateDistance(float lat1, float lon1, float lat2,
float lon2) {
float dLat = (float) Math.toRadians(lat2 - lat1);
float dLon = (float) Math.toRadians(lon2 - lon1);
float a = (float) (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));
float c = (float) (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
float d = (float) (earthRadius * c);
return d;
}
public static double distanceCalcByHaversine(GeoPoint startP, GeoPoint endP) {
double lat1 = startP.getLatitudeE6() / 1E6;
double lat2 = endP.getLatitudeE6() / 1E6;
double lon1 = startP.getLongitudeE6() / 1E6;
double lon2 = endP.getLongitudeE6() / 1E6;
double dLat = Math.toRadians(lat2 - lat1);
double dLon = Math.toRadians(lon2 - lon1);
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));
return earthRadius * c;
}
public static double distanceKm(double lat1, double lon1, double lat2,
double lon2) {
Log.d("slatitute", " " + lat1);
Log.d("slongi", " " + lon1);
Log.d("tlatitute", " " + lat2);
Log.d("tlongi", " " + lon2);
int EARTH_RADIUS_KM = 6371;
double lat1Rad = Math.toRadians(lat1);
double lat2Rad = Math.toRadians(lat2);
double deltaLonRad = Math.toRadians(lon2 - lon1);
return Math
.acos(Math.sin(lat1Rad) * Math.sin(lat2Rad) + Math.cos(lat1Rad)
* Math.cos(lat2Rad) * Math.cos(deltaLonRad))
* EARTH_RADIUS_KM;
}