如何使用gmap中的緯度經度計算iPhone中兩處之間的距離?使用gmap中的緯度經度計算iPhone中的兩個地方之間的距離iPhone
0
A
回答
6
可以使用CLLocation對象上下面的方法:
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
例如:
CLLocation* location_a;
CLLocation* location_b;
CLLocationDistance distance = [location_a distanceFromLocation:location_b];
0
0
您可以使用此方法。它取自http://wiki.forum.nokia.com/index.php/How_to_calculate_distance_between_two_landmarks,但我想這個數學對於iPhone來說也是一樣的。 :)
const TInt KEarthRadius = 6372795; // in meters
TReal64 YourClassName :: CalcDistance(TReal64 aLat1, TReal64 aLong1,
TReal64 aLat2, TReal64 aLong2)
{
TReal64 result = -1,
lat1Sin, lat2Sin, lat1Cos, lat2Cos, deltaLongCos, deltaLongSin;
if(Math :: Sin(lat1Sin, aLat1 * KPi/180) == KErrNone &&
Math :: Sin(lat2Sin, aLat2 * KPi/180) == KErrNone &&
Math :: Cos(lat1Cos, aLat1 * KPi/180) == KErrNone &&
Math :: Cos(lat2Cos, aLat2 * KPi/180) == KErrNone &&
Math :: Cos(deltaLongCos, (aLong2 - aLong1) * KPi/180) == KErrNone &&
Math :: Sin(deltaLongSin, (aLong2 - aLong1) * KPi/180) == KErrNone)
{
TReal64 a = lat2Cos * deltaLongSin,
b = lat1Cos * lat2Sin - lat1Sin * lat2Cos * deltaLongCos,
c = lat1Sin * lat2Sin,
d = lat1Cos * lat2Cos * deltaLongCos,
e = a * a + b * b,
f;
if(Math :: Sqrt(f, e ) == KErrNone)
{
e = f/(c + d);
if(Math :: ATan(f, e) == KErrNone)
{
while(f < 0)
f += KPi;
result = f * KEarthRadius;
}
}
}
return result;
}
0
CLLocation *userLoc = [[CLLocation alloc] initWithCoordinate:appDelegate.mapView2.userLocation.coordinate];
CLLocation *poiLoc = [[CLLocation alloc] initWithLatitude: [aPOI.latitude doubleValue] longitude: [aPOI.longitude doubleValue]];
double dist = [userLoc getDistanceFrom:poiLoc]/1000;
相關問題
- 1. 計算兩個緯度 - 經度點之間的距離? - 鈦
- 2. 兩個經緯度之間的距離
- 3. 如何計算經度和緯度兩點之間的距離?
- 4. 計算兩點之間的距離(經度,緯度)
- 5. 計算兩個長/經緯度之間的距離
- 6. 計算兩個緯度和經度地理座標之間的距離
- 7. 如何使用angulajs計算兩個緯度和經度之間的距離?
- 8. 分別計算兩個緯度和兩個經度之間的距離
- 9. 計算兩個緯度座標之間的距離/方位
- 10. 用於計算兩個緯度和經度之間距離的MySQL函數
- 11. 使用緯度經度和海拔(海拔)計算兩點之間的距離
- 12. 使用MapKit計算經緯度之間的距離
- 13. PIG:計算緯度和經度對之間的最大距離
- 14. Sql查詢計算2緯度和經度之間的距離
- 15. SQL Server計算2組經度/緯度列之間的距離
- 16. J2ME - 計算2緯度和經度之間的距離
- 17. 使用rethinkdb 2個經緯度點之間計算距離
- 18. IPhone - 經緯度的SQLite距離
- 19. 計算iPhone 2經度和緯度之間的航向
- 20. 測量兩個緯度/經度點之間的距離
- 21. 兩個經度和緯度之間的距離
- 22. 獲取兩個經度緯度點之間的駕駛距離
- 23. 經典ASP中兩個緯度/長點之間的距離
- 24. 如何使用相應的緯度和經度值計算兩個地點之間的距離?
- 25. 如何找到緯度/經度/緯度點之間的距離?
- 26. 在excel中,如何計算兩組大點與經緯度之間的距離?
- 27. 如何使用緯度和經度計算距離和方位?
- 28. 使用經度和緯度在mysql中計算距離
- 29. 使用iphone中的谷歌地圖計算兩個位置之間的距離
- 30. Android Maps v2 API ...如何計算兩個位置之間的距離(經緯度)