0
我一直在尋找這一段時間。我發現了很多帖子,並查看了文檔,但我無法正常工作。我已實施了核心位置,並且其工作沒有問題,即捕獲當前位置和計算距離
NSLog(@"Description: %@\n", [newLocation description]);
說明詳細信息顯示在日誌中。
我想捕捉當前的位置,當用戶點擊一個按鈕,當他們開始移動重新捕獲他們的位置間歇性。使用這些信息,我想計算起點和當前點之間的距離。
我知道我可以使用以下命令:
CLLocationDistance distance = [myLocation distanceFromLocation:restaurantLocation]
計算距離,但我不知道如何捕捉當前位置。
如果有人可以發佈一些很棒的示例代碼。我接近得到這個工作,只需要最後一步在線。
問候, 斯蒂芬
2部分:由於原來的職位,我做了一個有點陸侃的。詳情如下貼:
#import "MyCLController.h"
@implementation MyCLController
@synthesize locationManager;
@synthesize delegate;
- (id) init {
self = [super init];
if (self != nil) {
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self; // send loc updates to myself
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[self.delegate locationUpdate:newLocation];
CLLocation *item1 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
CLLocation *item2 = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];
int meters = [item1 getDistanceFrom:item2];
NSLog(@"Distance-d: %d", meters);
[item1 release];
[item2 release];
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
[self.delegate locationError:error];
}
- (void)dealloc {
[self.locationManager release];
[super dealloc];
}
@end
我說的對這裏計算距離或者我應該在NewWorkoutViewController.m那樣做,在locationUpdate方法?
我已經取得了一些進展,並按照上面所述實施了一些代碼,但還有一些問題。我已更新了我的原始帖子(請參閱第2部分)。 – Stephen 2010-09-01 10:55:49