iPhone GPS定位

iPhone GPS定位,iphone,objective-c,latitude-longitude,Iphone,Objective C,Latitude Longitude,我想在iPhone上用objective C获得我的经度和纬度。有人能指导我如何通过编程获得这些坐标吗 #import <Foundation/Foundation.h> @class CLLocationManager; @interface CLLocationController : NSObject { CLLocationManager *locationManager; } @property (nonatomic, retain) CLLocationM

我想在iPhone上用objective C获得我的经度和纬度。有人能指导我如何通过编程获得这些坐标吗

#import <Foundation/Foundation.h>

@class CLLocationManager;

@interface CLLocationController : NSObject {
    CLLocationManager *locationManager; 
}

@property (nonatomic, retain) CLLocationManager *locationManager; 

@end

使用CLLocationManager,将对象设置为委托并开始获取更新

self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 
self.locationManager.delegate = self; 
[self.locationManager startUpdatingLocation]; 
然后实现委托:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation { 
  NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]); 
  NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude]); 
} 

developer.apple.com阅读文档
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation { 
  NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]); 
  NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude]); 
}