6

Is it possible to calculate the distance between 2 close points on iOS using Apple map framework or Google framework? For example, i want to get the distance between this 2 blu point with the highest accuracy possible.

enter image description here

Using google maps or apple maps can i get the 2 coordinate with a lot of digit? how can i calculate the distance in centimeters or millimeters?

Adrian Bobrowski
  • 2,681
  • 1
  • 16
  • 26
Fiorelo Odobashi
  • 121
  • 1
  • 1
  • 11
  • 1
    Yes you get accurate enough data, then use https://stackoverflow.com/a/7175724/1971013 – meaning-matters Aug 06 '17 at 15:52
  • using CLLocationDistance does it approximates or give me the real distance in meters: it will return for example 30.21m or 30.00m ? – Fiorelo Odobashi Aug 06 '17 at 16:01
  • 1
    Possible duplicate of [GPS coordinates in degrees to calculate distances](https://stackoverflow.com/questions/6994101/gps-coordinates-in-degrees-to-calculate-distances) – Fernando Aug 06 '17 at 16:27
  • Given that specialized equipment is generally needed to record the location of a point to mm accuracy, it is unlikely that measuring the distance between these two locations with mm precision will result in a measurement accurate to the mm - unless of course they were surveyed points with a known datum. – Andrew Reid Aug 06 '17 at 18:02
  • @AndrewReid Thanks for your answer. That point will be selected in map (like google maps when you touch for a while the screen). I don't need a GPS that provide me an accurate localization. – Fiorelo Odobashi Aug 06 '17 at 19:58

2 Answers2

37

Try this -

let coordinate0 = CLLocation(latitude: 5.0, longitude: 5.0)
let coordinate1 = CLLocation(latitude: 5.0, longitude: 3.0)
let distanceInMeters = coordinate0.distance(from: coordinate1)
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
3

Yes, you'll get accurate enough position information. CLLocation has a distance(from: CLLocation) function that does the trick and gives accurate results also for short distances.

meaning-matters
  • 21,929
  • 10
  • 82
  • 142