java radians,Java:关于弧度,Math.cos,Math.sin,double和long的问题

I need to implement the harvesine distance in my java code.

I found this snippet in Javascript, and I need to convert it to java.

How can I convert latitude and longitude to radians in Java ?

Math.sin wants a double in Java. Should I pass the previously converted value in radians or not ?

Math.sin and Math.cos return long. Should I declare a as long and pass it to Math.sqrt or convert it to double ?

thanks

dLat = (lat2-lat1).toRad();

dLon = (lng2-lng1).toRad();

a = Math.sin(dLat/2) * Math.sin(dLat/2) +

Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *

Math.sin(dLon/2) * Math.sin(dLon/2);

c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

d = R * c;

return d;

解决方案

I've found the solution here:

你可能感兴趣的:(java,radians)