Find current location in iphone or ipad app

Hi, There is usually requirement to find the current location in google map.
Specially many iphone app or ipad app provide the current location of the user in the application
Here is the steps to find the current location in the MKMapView
1. add the CoreLocation.Framework
2. then  #import <CoreLocation/CLLocationManagerDelegate.h> 
3. set the delegate CLLocationManagerDelegate
4. write the following code in your iphone or ipad app


CLLocationManager   *locmanager;
BOOL    wasFound;



- (void)viewDidLoad
{
    [super viewDidLoad];
    
    locmanager = [[CLLocationManager alloc] init]; 
[locmanager setDelegate:self]; 
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];
[locmanager startUpdatingLocation];    
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
    if (wasFound) return
wasFound = YES;
    
CLLocationCoordinate2D loc = [newLocation coordinate];
    NSLog(@"current longitude = %f  ,   current latitude = %f",loc.longitude,loc.latitude);
}



0 comments:

Post a Comment

Powered by Blogger.
Twitter Delicious Facebook Digg Stumbleupon Favorites More