When calculating the distance from latitude and longitude, it is not difficult if the roundness of the earth is taken into consideration and the earth can be approximated to a true sphere.
from math import sin, cos, acos, radians
earth_rad = 6378.137
def latlng_to_xyz(lat, lng):
rlat, rlng = radians(lat), radians(lng)
coslat = cos(rlat)
return coslat*cos(rlng), coslat*sin(rlng), sin(rlat)
def dist_on_sphere(pos0, pos1, radius=earth_rad):
xyz0, xyz1 = latlng_to_xyz(*pos0), latlng_to_xyz(*pos1)
return acos(sum(x * y for x, y in zip(xyz0, xyz1)))*radius
Osaka = 34.702113, 135.494807
Tokyo = 35.681541, 139.767103
London = 51.476853, 0.0
print(dist_on_sphere(Osaka, Tokyo)) # 403.63km
print(dist_on_sphere(London, Tokyo)) # 9571.22km
If you want to calculate more accurately, you need to approximate it with a spheroid, and there is room for improvement such as the error or large in the vicinity of 1 for the ʻacos` function, but for casual purposes, this is enough.
Anyway, it's not that complicated even if you consider the roundness. For reference when APIs and libraries cannot be used.