试图获得CLLocationCoordinate2D纬度和经度

时间:2010-01-21 20:12:59

标签: iphone objective-c sdk

您好我试图获取用户所在位置的纬度和经度值 没有地图显示所以基本上它将在后台运行。我想我必须使用地图工具包,但有任何例子吗?

1 个答案:

答案 0 :(得分:2)

如果您不想要地图,则不需要MapKit。只需使用CLLocationManager

- (id) init {
  if (self = [super init]) {
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    [locationManager startUpdatingLocation];
  }
  return self;
}

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)location fromLocation:(CLLocation *)oldLocation {
  NSLog(@"lat:%f lon:%f", location.coordinate.latitude, location.coordinate.longitude);
}