I want to compute the "MANHATTAN DISTANCE" also called "CITY BLOCK DISTANCE" among pairs of coordinates with LAT, LNG.
Following this post Manhattan Distance for two geolocations I had computed the distance using the haversine formula:
source = (45.070060, 7.663708)
target = (45.068250, 7.663492)
This is my computation:
from math import radians, sin, asin, sqrt, atan2
# convert decimal degrees to radians
lat1, lon1, lat2, lon2 = map(radians, [source[0], source[1], target[0], target[1]])
#haversine formula for delta_lat
dlat = lat2 - lat1
a = sin(dlat / 2) ** 2
c = 2 * atan2(sqrt(a), sqrt(1-a)))
r = 6371
lat_d = c * r
# haversine formula for delta_lon
dlon = lon2 - lon1
a = sin(dlon / 2) ** 2
c = 2 * atan2(sqrt(a), sqrt(1-a))
r = 6371
lon_d = c * r
print lat_d + lon_d
The problem is that my result is 225m, while Google Maps says 270m.
Trying again to compute the distance among
source = (45.070060, 7.663708)
target = (45.072800, 7.665540)
the result I obtained is 508m while Google Maps says 350m.
I will appreciate if someone can help me understanding what is wrong here and how to improve this solution which is far from being acceptable. Thank you!