Implementation of haversine formula.