This might not be the most efficient method of doing it, but it will work.
Your two locations specified by latitude and longitude can be considered vectors. Assuming that the coordinates have been converted into cartesion coordinates, calculate the dot product of the two vectors.
Given v1 = (x1, y1, z1) and v2 = (x2, y2, z2), then ...
v1 dot v2 = magnitude(v1) * magnitude(v2) * cos (theta)
Conveniently, the magnitude of v1 and v2 will be the same ... the radius of the earth (R).
x1*x2 + y1*y2 + z1*z2 = R*R*cos(theta)
Solve for theta.
theta = acos ((x1*x2 + y1*y2 + z1*z2) / (R * R));
Now you have angle between the two vectors in radians. The distance betwen the two points when travelling across the surface of earth is thus ...
distance = theta * R.
There is probably an easier way to do this entirely within the context of spherical coordinates, but my math in that area is too fuzzy--hence the conversion to cartesian coordinates.
To convert to cartesian coordinates ...
Let alpha be the latitude, and beta be the longitude.
x = R * cos (alpha) * cos (beta)
y = R * sin (alpha)
z = R * cos (alpha) * sin (beta)
Don't forget that the math function typically deal in radians, and the latitude/longitude deal in degrees.