我在這裏看到了許多currentLocation問題,但我試圖使用兩個獨立的IBActions設置兩個點,因爲從我的理解中,Core Location updateLocation方法無法測量用戶選擇的兩個點之間的距離。例如,如果人站在鎮的一邊,他們可以點擊一個按鈕,它將設置爲locA,然後他們去鎮的另一邊,點擊一個不同的按鈕,它將設置爲locB,當他們點擊第三個按鈕它會計算兩者之間的距離。關於如何實現這個的任何想法?CLLocation當前位置獲取位置
我試着這樣做:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)setPointOne{
locA = [[CLLocation alloc] initWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude];
}
- (IBAction)setPointTwo{
locB = [[CLLocation alloc] initWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude];
}
- (IBAction)calculateDistance{
CLLocationDistance distance = [locA distanceFromLocation:locB];
totalDistance.text = [NSString stringWithFormat:@"Distance: %f Meters", distance];
[locA release];
[locB release];
}
當我做這一切的按鈕導致崩潰
繼承人的崩潰日誌:
- [視圖控制器位置]:無法識別的選擇發送到實例 0x1fd36b60 2012-11-10 16:38:38.567 MeasureIt [3043:907] *終止 應用程序由於未捕獲異常'NSInvalidAr gumentException」,原因: ' - [視圖控制器位置]:無法識別的選擇發送到實例 0x1fd36b60' *第一擲調用堆棧:(0x3a4f42a3 0x343e397f 0x3a4f7e07 0x3a4f6531 0x3a44df68 0x337110a5 0x33711057 0x33711035 0x337108eb 0x33710de1 0x336395f1 0x33626801 0x3362611b 0x388095a3 0x388091d3 0x3a4c9173 0x3a4c9117 0x3a4c7f99 0x3a43aebd 0x3a43ad49 0x388082eb 0x3367a2f9 0xd5a27 0x37ca6b20)的libC++ abi.dylib:終止叫 拋出一個異常(LLDB)
您需要提問。你剛纔發表了一些聲明。你想問什麼? – rmaddy
就像你解釋的那樣執行它。如果您遇到實際問題,請告訴我們您嘗試了什麼以及您遇到什麼問題。 – sosborn
崩潰日誌說什麼? (順便提一下,你應該在提問時一直包括這個)。 – sosborn