from ortools.constraint_solver import routing_enums_pb2 from ortools.constraint_solver import pywrapcp from math import asin, cos, radians, sin, sqrt def distance_between(lat1, lng1, lat2, lng2): """ Calculate the great circle distance (in meters) between two points on the earth (specified in decimal degrees) """ # convert decimal degrees to radians lng1, lat1, lng2, lat2 = map(radians, [lng1, lat1, lng2, lat2]) # haversine formula dlon = lng2 - lng1 dlat = lat2 - lat1 a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2 c = 2 * asin(sqrt(a)) r = 6371 * 1000 # Radius of earth in kilometers. Use 3956 for miles return c * r