Last active
September 27, 2016 15:39
-
-
Save fjcunha/cd6f536a59940900bc15435ddd7f100f to your computer and use it in GitHub Desktop.
Function to calcule distance in meters
This file contains 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
public String calculeDistance(){ | |
String distance = null; | |
double earthR = 6371; | |
double lati = Math.PI/180*(mMyLatitude - mPoi.getPoiLatitude()); | |
double longi = Math.PI/180*(mMyLongitude - mPoi.getPoiLongitude()); | |
double a = | |
Math.sin(lati/2) * Math.sin(lati/2)+ | |
Math.cos(Math.toRadians(mPoi.getPoiLatitude())) * Math.cos(Math.toRadians(mMyLatitude)) * | |
Math.sin(longi/2) * Math.sin(longi/2); | |
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); | |
double d = earthR * c * 1000; | |
Log.i("Distancia do ponto: ", "" + d + " Km"); | |
distance = ""+d; | |
((TextView) findViewById(R.id.markerDistance)).setText("A "+Math.ceil(d)+" metros."); | |
return distance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment