2009-09-03 43 views
0

我有一個來自Core Location的座標,並且想要計算給定軸承和距離的座標,以km爲單位。根據度數和距離獲取新座標+1

我覺得這是這裏的公式。 http://www.movable-type.co.uk/scripts/latlong.html

公式:
LAT2 = ASIN(SIN(LAT1)* COS(d/R)+ COS(LAT1)* SIN(d/R)* COS(θ))
lon2 = lon1 + ATAN2(SIN(θ)* SIN(d/R)* COS(LAT1), COS(d/R)-sin(LAT1)* SIN(LAT2))
d/R是 的角距(以弧度爲單位), 其中d是行進距離, R是地球半徑

我有以下代碼。

 CLLocationCoordinate2D linecoordstart; 
    linecoordstart = [[existingpoints objectAtIndex:i] coordinate]; 
    NSString *bearing = [[existingpoints objectAtIndex:i] heading]; 
    NSString *distance = [[existingpoints objectAtIndex:i] distance]; 
CLLocationCoordinate2D sourceCoordinate; 
       sourceCoordinate = [[existingpoints objectAtIndex:i] coordinate]; 


NSLog(@"%f,%f",sourceCoordinate.latitude,sourceCoordinate.longitude); 
    float lat2; 
int d = 5; 
int R = 6371; 
lat2 = asin(sin(sourceCoordinate.latitude)cos(d/R) + cos(sourceCoordinate.latitude)sin(d/R)cos(180)); 
NSLog(@"%f",lat2); 

我想能夠通過它是一個軸承,它是目前的NSString和距離。我無法弄清楚如何在我的生活中使用Math.h函數!

回答

1

NSString轉換爲數字,可以使用:

NSString* intNum = @"123"; 
NSString* floatNum = @"123.456"; 
int iv = [intNum intValue]; 
float fv = [floatNum floatValue]; 

此外,雙方dR被定義爲int(而不是float)。在你的代碼d/R將剪輯值爲整數0.可能想讓他們float(並用浮點值初始化它們)。

相關問題