Distance between 2 points?

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Distance between 2 points?

Postby antonioxerez » Mon Apr 04, 2011 9:27 am

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 !
antonioxerez
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 21, 2011 9:26 pm

Top

Re: Distance between 2 points?

Postby antonioxerez » Wed Apr 06, 2011 10:31 am

Ok thank you again ! distanceTo, from class Location is what i was looking for !
antonioxerez
Freshman
Freshman
 
Posts: 8
Joined: Mon Mar 21, 2011 9:26 pm

Re: Distance between 2 points?

Postby schofeild » Wed Apr 06, 2011 4:19 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
schofeild
Developer
Developer
 
Posts: 40
Joined: Wed Jul 21, 2010 12:08 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: MSN [Bot], Yahoo [Bot] and 1 guest