Pages

Saturday, April 16, 2011

Find Current lat/lon with Iphone sdk:

In .h file:
#import
CLLocationManager *locationManager;
NSString *lat;
NSString *lon;
@property (nonatomic,retain) NSString *lat;
@property (nonatomic,retain) NSString *lon;
In .m file:
@synthesize lat,lon;
// Get Current Lat and lon
[self getCurrentLatLon];
-(void) getCurrentLatLon
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;

locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];

}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{

self.lat = [NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];
self.lon = [NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
}



Happy programming..............

No comments:

Post a Comment