开发者

Retrieve current lat/long from iphone without displaying a map

I need to acquire the c开发者_运维技巧urrent lat/long from the iphone without displaying a map.

Can this be accomplished??

objective C please.

thank you tony


Look at CLLocationManager. You can simply create an instance, setting your controller as delegate, start the instance to acquire your location, and in your CLLocationManagerDelegate delegate methods to handle the results, you can access the coordinates. No map required.


- (void)startUpdates {
    coreManager = [[CLLocationManager alloc] init];
    coreManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    coreManager.delegate = self;
    [coreManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    // newLocation is location from gps...
    // you'll need to stop coreManager updating when you have a good fix
}

See the Apple docs for details.


CLLocationManager is the interface you must use in order to retrieve current Lat/Long

Below is the code:

locationManager = [[CLLocationManager alloc] init]; 
locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
locationManager.distanceFilter = DISTANCE_FILTER_VALUE;
locationManager.delegate = self; 
[locationManager startUpdatingLocation];


Just use CLLocationManager for it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜