2017-08-06 139 views
1

是否可以使用Apple地圖框架或Google框架計算iOS上2個關閉點之間的距離?例如,我想要獲得這2個藍點之間的距離,並儘可能提供最高的準確度。計算iOS上地圖上2點之間的距離

enter image description here

使用谷歌地圖或地圖的蘋果我可以得到2有很多數字的協調?我如何計算以釐米或毫米爲單位的距離?

+1

是的,你得到足夠準確的數據,然後使用https://stackoverflow.com/a/7175724/1971013 –

+0

使用CLLocationDistance它近似或給我真正的米距離:它將返回例如30.21米或30.00米? –

+1

[GPS座標以度來計算距離](https://stackoverflow.com/questions/6994101/gps-coordinates-in-degrees-to-calculate-distances) – Fernando

回答

5

試試這個 -

let coordinate0 = CLLocation(latitude: 5.0, longitude: 5.0) 
let coordinate1 = CLLocation(latitude: 5.0, longitude: 3.0) 
let distanceInMeters = coordinate0.distance(from: coordinate1) 
+0

okey謝謝你,我認爲這個功能只能給我以米爲單位的近似距離(例如:12.32米 - > 12.00米)。我試了一下,它完美的工作! –

+0

很高興工作!如果它幫助你,那麼請接受答案:) –

1

是的,你會得到足夠準確的位置信息。 CLLocation有一個distance(from: CLLocation)函數可以實現這個技巧,並且對於短距離也有精確的結果。