回答
的CoreLocation Framework提供的能力,制定出的距離,以米爲單位,兩點之間:
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
可以初始化一個CLLocation
對象與緯度和經度:
- (id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude
感謝之間的最短距離...它? – Rambo 2009-10-29 12:13:52
這是CLLocation框架的一項任務。如果已知座標爲2點,則可以創建(如果您還沒有它們)2個CLLocation對象並使用它們查找它們之間的距離
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
方法。
如果你有兩個CLLocation對象,你可以做:
[location1 getDistanceFrom:location2];
然而,這只是點至點。如果你想要一條特定路線上的距離,那麼,這是另一個魚的水壺。
我不是熟悉iPhone的開發,但這裏是使用Haversine公式計算兩點之間距離的C#代碼:
/// <summary>
/// Computes the distance beween two points
/// </summary>
/// <param name="P1_Latitude">Latitude of first point (in radians).</param>
/// <param name="P1_Longitude">Longitude of first point(in radians).</param>
/// <param name="P2_Latitude">Latitude of second point (in radians).</param>
/// <param name="P2_Longitude">Longitude of second point (in radians).</param>
protected double ComputeDistance(double P1_Longitude, double P1_Latitude, double P2_Longitude, double P2_Latitude, MeasurementUnit unit)
{
double dLon = P1_Longitude - P2_Longitude;
double dLat = P1_Latitude - P2_Latitude;
double a = Math.Pow(Math.Sin(dLat/2.0), 2) +
Math.Cos(P1_Latitude) *
Math.Cos(P2_Latitude) *
Math.Pow(Math.Sin(dLon/2.0), 2.0);
double c = 2 * Math.Asin(Math.Min(1.0, Math.Sqrt(a)));
double d = (unit == MeasurementUnit.Miles ? 3956 : 6367) * c;
return d;
}
的MeasurementUnit被定義爲:
/// <summary>
/// Measurement units
/// </summary>
public enum MeasurementUnit
{
Miles,
Kilometers
}
感謝vbocan的回覆 – Rambo 2009-10-29 13:14:36
這要看樣的區別,你想同時擁有點之間。在地圖上,我認爲你不想要空中距離。那麼你應該檢查http://iosboilerplate.com/
如果你還想使用空中距離,使用核心位置。
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
返回從接收者位置到指定位置的距離(以米爲單位)。 (不推薦使用iOS中使用3.2的 distanceFromLocation:
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
- 1. 如何計算谷歌地圖中兩點之間的距離?
- 2. 無法計算谷歌地圖中兩點之間的距離
- 3. 使用iphone中的谷歌地圖計算兩個位置之間的距離
- 4. 如何計算谷歌地圖中兩個座標之間的距離?
- 5. 機器人,兩地之間的計算距離,谷歌距離矩陣
- 6. 谷歌地圖API總距離計算
- 7. 谷歌地圖距離計算
- 8. 使用谷歌地圖計算距離
- 9. /谷歌地圖來計算距離
- 10. 谷歌應用程序腳本地圖API兩點之間的距離計算
- 11. 谷歌地圖 - 如何獲得米之間的兩點之間的距離?
- 12. 谷歌地圖:指定路線上兩點之間的距離
- 13. 谷歌地圖API - V3兩個多邊形之間的距離
- 14. 使用谷歌地圖api工作兩點之間的距離?
- 15. 兩點之間的距離谷歌地圖a是undefined api v3
- 16. 兩地的距離計算
- 17. 如何計算兩個地址之間的距離
- 18. 如何計算兩地之間的距離?
- 19. 如何使用php計算兩地之間的距離?
- 20. 如何計算兩個地理點之間的距離
- 21. 時間和距離計算谷歌地圖路由
- 22. 計算bing地圖中兩點之間的距離
- 23. 如何在谷歌地圖上獲取六十進制數,並且計算兩個兩性之間的距離?
- 24. 使用python計算谷歌地圖中2點之間的距離
- 25. 谷歌地圖距離計算器與地理位置
- 26. 計算沒有Google地圖的地址之間的距離
- 27. 的Xcode在谷歌兩個地點之間的距離映射
- 28. 谷歌地圖v3距離
- 29. 谷歌地圖距離API
- 30. 如何計算兩點之間的預計到達時間 - Swift /谷歌地圖
是這兩個地方,或一種特殊路徑(公路,鐵路,河流,...) – 2009-10-29 12:27:50