Update Location in Mapview Xcode

流过昼夜 提交于 2019-12-02 12:31:01
Anbu.Karthik

set your location track in

//create location manager object
locationManager = [[CLLocationManager alloc] init];

//there will be a warning from this line of code
[locationManager setDelegate:self];

//and we want it to be as accurate as possible
//regardless of how much time/power it takes
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

//set the amount of metres travelled before location update is made
[locationManager setDistanceFilter:50];

and add

if ([CLLocationManager locationServicesEnabled]) {
    [self.locationManager startUpdatingLocation];
}

Update

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *location = locations.lastObject;
NSLog(@"%@", location.description);

 //In here you get all details like

   NSLog(@"latitude = %@",location.coordinate.latitude);
   NSLog(@"longitude = %@",location.coordinate.longitude);
   NSLog(@"altitude = %@",location.altitude);
   NSLog(@"horizontalAccuracy = %@",location.horizontalAccuracy);
   NSLog(@"verticalAccuracy = %@",location.verticalAccuracy);
   NSLog(@"timestamp = %@",location.timestamp);
   NSLog(@"speed = %@",location.speed);
   NSLog(@"course = %@",location.course);

}
  1. You have to make object of CLLocationManager when application starts and set it's delegate

Add the below code to get user's current location

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
  1. Now add the delegate of CLLocationManagaer that is didUpdateToLocation and add the following code in that.

    CLLocationDistance meters = [newLocation distanceFromLocation:oldLocation];

    if(meters==50)
    {
        // CALL YOU WEBSERVICE
    }
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!