Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different distance between two points on iOS and Android

I'm trying to measure the distance between two points (longitude, latitude). My problem is that I get different results on iOS then on Android.

I've checked it with this site and the result was that the Android values are correct.

I'm using this MapKit method to get the distance in iOS: distanceFromLocation:

Here are my test locations:

P1: 48.643798, 9.453735 P2: 49.495150, 9.782150

Distance iOS: 97717 m Distance Android: 97673 m

How is this possible and how can I fix this?

like image 379
MoFuRo Avatar asked Feb 09 '12 14:02

MoFuRo


People also ask

How do you find the distance between 2 points?

Distance between two points is the length of the line segment that connects the two points in a plane. The formula to find the distance between the two points is usually given by d=√((x2 – x1)² + (y2 – y1)²).


2 Answers

So I was having a different issue and stumbled upon the answer to both of our questions:

On iOS you can do the following:

 meters1 = [P1 distanceFromLocation:P2]
 // meters1 is 97,717

 meters2 = [P2 distanceFromLocation:P1]
 // meters2 is 97,630

I've searched and searched but haven't been able to find a reason for the difference. Since they are the exact same points, it should show the same distance no matter which way you are traveling. I submitted it to Apple as a bug and they closed it as a duplicate but have still not fixed it. I would suggest to anyone who wants this to be fixed to also submit it as a bug.

In the meantime, the average of the two is actually the correct value:

 meters = (meters1 + meters2)/2
 // meters (the average of the first two) is 97,673

Apparently Android does not have this problem.

like image 189
lnafziger Avatar answered Sep 24 '22 17:09

lnafziger


The longitude and latitude are not all that you need. You have to use the same reference model like WGS84 or ETRS89. The earth is not an exact ellipsoid, so you need models, none of the models are entirely exact, and depending on which model you use, distances are somewhat different.

Please make sure you use the same reference for iOS and Android.

like image 30
Oliver Hankeln Avatar answered Sep 25 '22 17:09

Oliver Hankeln