I want to track the location of my ios device and notify in the app if it crosses certain kilometres.Suppose I want to notify if it crosses 1 km from current location of device. Please help I am new in iOS programming.
I am able to fetch the current location. Please help.
Here what I am able to do.
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate=self;
// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLLocationAccuracyBestForNavigation;//constant update of device location
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization];
[self.locationManager startUpdatingLocation];
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
self.userLocation = userLocation;
MKCoordinateSpan coordinateSpan; coordinateSpan.latitudeDelta = 0.3f; coordinateSpan.longitudeDelta = 0.3f;
MKCoordinateRegion regionToShow; regionToShow.center = userLocation.coordinate; regionToShow.span = coordinateSpan;
[self.mapView setRegion:regionToShow animated:YES];
MKPointAnnotation *point=[[MKPointAnnotation alloc]init];
point.coordinate=userLocation.coordinate;
point.title=@"where Am I";
point.subtitle=@"YOU are Here";
[self.mapView addAnnotation:point];
}