Created
July 22, 2014 09:19
-
-
Save nishitpatel/f61c002310635852db20 to your computer and use it in GitHub Desktop.
Find distance between two coordinates in km.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private float getDistanceBetweenCoordinates(double latitude1, | |
double longitude1, double latitude2, double longitude2) { | |
Location locationA = new Location("point A"); | |
locationA.setLatitude(latitude1); | |
locationA.setLongitude(longitude1); | |
Location locationB = new Location("point B"); | |
locationB.setLatitude(latitude2); | |
locationB.setLongitude(longitude2); | |
float meter = locationA.distanceTo(locationB); | |
float distance = meter / 1000; | |
String d = String.format("%.2f", distance); | |
return Float.parseFloat(d); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment