如何在Iphone中获取GPS位置

Roy*_*nto -4 iphone xcode objective-c ipad

你能告诉我,我怎样才能在iPhone上获得GPS定位.

谢谢.

Meh*_*tri 13

实现CLLocationManagerDelegate并编写此函数并在viewController的viewDidLoad方法中调用它.

-(void)startLocationManager
{
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate=self;
    locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
    [locationManager startUpdatingLocation];
}

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
 {      
    CLLocationCoordinate2D coordinate = [newLocation coordinate];
    double dblLatitude = coordinate.latitude;
    double dblLongitude = coordinate.longitude;     
 }
Run Code Online (Sandbox Code Playgroud)