Currently I am working on GPS related project. and every day I am exploring new things. Now I realize that GPS is very interesting technology and we can make lot of useful things by using GPS.
The new thing today I learned is, finding distance between two points. Previously I was thinking that, it may be difficult but, thankfully there is a much simpler way to figure out distances between two points on a map: the distanceTo() method in the Location class. Using this handy little method, we can quickly find out the distance between two locations:
double distance; Location locationA = new Location("point A"); locationA.setLatitude(latA); locationA.setLongitude(lngA); Location locationB = new Location("point B"); locationB.setLatitude(latB); LocationB.setLongitude(lngB); distance = locationA.distanceTo(locationB);
One thing to note is that the distanceTo() method returns the distance in meters, so you will need to do the appropriate calculations if you want your distances in other units.