Thursday 22 May 2014

Get latitude and longitude of current location

Add core location framework and import them.

Now in .h file add delegate CLLocationManagerDelegate.

CLLocationManager *locationManager;
    double current_lati;

    double current_longi;


In .m class

-(void)getCurrentLatLon
{
    
    // locationManager update as location

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    [locationManager startUpdatingLocation];
    CLLocation *location = [locationManager location];

    // Configure the new event with information from the location
    current_lati = location.coordinate.latitude;
    current_longi = location.coordinate.longitude;
    
    NSLog(@"dLongitude : %f", current_longi);
    NSLog(@"dLatitude : %f", current_lati);
    
    
}

No comments:

Post a Comment