Wednesday, 20 February 2013

To find current latitude and longitude in IOS




First need to add core location.framework.

then add a instance variable as below:

 CLLocationManager *locationManager;

Then add below code :




locationManager = [[CLLocationManager alloc] init];
        locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
        locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
        [locationManager startUpdatingLocation];
        latitude=[NSString stringWithFormat:@"%f", locationManager.location.coordinate.latitude];
        longitude=[NSString stringWithFormat:@"%f",locationManager.location.coordinate.longitude];
        
          NSLog(@"%@",latitude);
          NSLog(@"%@",longitude);