android - Spherical Cosinus Haversine Formula -


so write function haversine formula calculate distance 2 coordinate, , find code dont know how write in android. here function created.

private double sphericalcosinus(double lat1, double long1, double lat2,         double long2) {     //formula } 

and formula one, there tutorial tell me use math libarary write code wrong because apps didnt show location. here formula get

=(6371.1*((2*asin(sqrt((sin((radians(lat2)-radians(lat1))/2)^2)+cos(radians(lat2))*cos(radians(lat1))*(sin((radians(long2)-radians(long1))/2)^2)))))) 

by power of find , replace:

private double sphericalcosinus(double lat1, double long1, double lat2, double long2) {     return 6371.1*((2 *          math.asin(             math.sqrt(                 (math.sin(math.pow((math.toradians(lat2)-math.toradians(lat1))/2),2.0)) +                  math.cos(math.toradians(lat2)) *                  math.cos(math.toradians(lat1)) *                 (math.sin(math.pow(math.toradians(long2)-math.toradians(long1))/2),2.0)             )         )     )); } 

https://developer.android.com/reference/java/lang/math.html


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -