Let's say I have two locations represented by latitude and longitude.
Location 1 : 37.5613
, 126.978
Location 2 : 37.5776
, 126.973
How can I calculate the distance using Manhattan distance ?
Edit : I know the formula for calculating Manhattan distance like stated by Emd4600
on the answer which is |x1-x2| - |y1-y2|
but I think it's for Cartesian. If it is can be applied that straight forward |37.5613-37.5776| + |126.978-126.973|
what is the distance unit of the result ?
Given a plane with
p1
at(x1, y1)
andp2
at(x2, y2)
, it is, the formula to calculate the Manhattan Distance is|x1 - x2| + |y1 - y2|
. (that is, the difference between the latitudes and the longitudes). So, in your case, it would be:EDIT: As you have said, that would give us the difference in latitude-longitude units. Basing on this webpage, this is what I think you must do to convert it to the metric system. I haven't tried it, so I don't know if it's correct:
First, we get the latitude difference:
Now, the longitude difference:
Now, we will use the
haversine
formula. In the webpage it usesa = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
, but that would give us a straight-line distance. So to do it with Manhattan distance, we will do the latitude and longitude distances sepparatedly.First, we get the latitude distance, as if longitude was 0 (that's why a big part of the formula got ommited):
Now, the longitude distance, as if the latitude was 0:
Finally, just add up
|latitudeDistance| + |longitudeDistance|
.