#include<iostream>
#include<cmath>
#define pi 3.1415926535897
using namespace std;
int main ()
{
double lat1;
double long1;
double lat2;
double long2; // initilaise values
double latz;
double longz;
double a = 0;
double c = 0;
double distance = 0;
double x = 0;
double y = 0;
cout << "enter lattitude 1 " << endl;
cin >> lat1;
cout << "enter longtitude 1 " << endl;
cin >> long1;
cout << "enter lattitude 2 " << endl;
cin >> lat2;
cout << "enter longtitude 2 " << endl;
cin >> long2;
lat1=lat1*(pi/180);
long1=long1*(pi/180);
lat2=lat2*(pi/180);
long2=long2*(pi/180);
latz = (lat2 - lat1)*(pi/180);
longz = (long2 - long1)*(pi/180);
x= pow(cos(lat2)*sin(longz),2.0) + pow((cos(lat1)*sin(lat2)) - sin(lat1)*cos(lat2)*cos(longz),2.0);
y= (sin(lat1)*sin(lat2)) + (cos(lat1)*cos(lat2)*cos(longz));
a = sqrt(x);
c = 2* atan2(x ,y);
distance = 6371.009 * c; //distance in km
cout << "Distance is: " << distance <<"km" << endl;
}
getting different answers for online caalculators & from my own code for example, if choose lat1,long1 &lat2,long 2 as 2,1 & 4,3 respectively i get roughly 15.53km, whilst on online calculators it comes out as 314.3km. this is the online version http://www.movable-type.co.uk/scripts/latlong.html any idea where i'm going wrong?