I'm going to find the distance between two cities using Haversine formula. below is the code in VC++.
But I could't find the distance between the points (18.567367, -68.363431) and (33.636719,-84.428067) [first value is latitude, second is longitude]. It gives something like -1.#IND.
Could you please tell me how to deal with this issue?
below is the code:
double deg2rad(double deg) {
return (deg * pi / 180);
};
double TravelDistance(double lat1d, double lon1d, double lat2d, double lon2d) {
double lat1r, lon1r, lat2r, lon2r, u, v,dblDistance;
lat1r = deg2rad(lat1d);
lon1r = deg2rad(lon1d);
lat2r = deg2rad(lat2d);
lon2r = deg2rad(lon2d);
u = sin(lat2r - lat1r);
v = sin(lon2r - lon1r);
return ( 2.0 * earthRadiusKm * asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v)))};
Thank in advance....!!