Hi again !

Im trying to find a method which shows the distance between 2 points (current position and other point, actually)

Does anybody know anything about it? and/or showing a rect between those 2 points??

Thanks !

3 posts
• Page **1** of **1**

Hi again !

Im trying to find a method which shows the distance between 2 points (current position and other point, actually)

Does anybody know anything about it? and/or showing a rect between those 2 points??

Thanks !

Im trying to find a method which shows the distance between 2 points (current position and other point, actually)

Does anybody know anything about it? and/or showing a rect between those 2 points??

Thanks !

- antonioxerez
- Freshman
**Posts:**8**Joined:**Mon Mar 21, 2011 9:26 pm

Ok thank you again ! distanceTo, from class Location is what i was looking for !

- antonioxerez
- Freshman
**Posts:**8**Joined:**Mon Mar 21, 2011 9:26 pm

use this method:

public static double EARTH_RADIUS_KM = 6384;// km

public static double calculateDistanceMeters(double aLong, double aLat,

double bLong, double bLat) {

double d2r = (Math.PI / 180);

double dLat = (bLat - aLat) * d2r;

double dLon = (bLong - aLong) * d2r;

double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)

+ Math.cos(aLat * d2r) * Math.cos(bLat * d2r)

* Math.sin(dLon / 2) * Math.sin(dLon / 2);

double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

return EARTH_RADIUS_KM * c * 1000;

}

the distance will be in meters

public static double EARTH_RADIUS_KM = 6384;// km

public static double calculateDistanceMeters(double aLong, double aLat,

double bLong, double bLat) {

double d2r = (Math.PI / 180);

double dLat = (bLat - aLat) * d2r;

double dLon = (bLong - aLong) * d2r;

double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)

+ Math.cos(aLat * d2r) * Math.cos(bLat * d2r)

* Math.sin(dLon / 2) * Math.sin(dLon / 2);

double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

return EARTH_RADIUS_KM * c * 1000;

}

the distance will be in meters

- schofeild
- Developer
**Posts:**40**Joined:**Wed Jul 21, 2010 12:08 pm

3 posts
• Page **1** of **1**

Users browsing this forum: No registered users and 2 guests