-(void)viewDidAppear:(BOOL)animated{
//new region
//regionMonitoring
if ([CLLocationManager regionMonitoringAvailable]){
NSNumber *eventLatitude = [event latitude];
NSNumber *eventLongitude = [event longitude];
CLLocation *pinLocation = [[CLLocation alloc]initWithLatitude:[eventLatitude doubleValue] longitude:[eventLongitude doubleValue]];
CLLocationCoordinate2D location = pinLocation.coordinate;
CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:location radius:10.0 identifier:@"onePin"];
[locationManager startMonitoringForRegion:region];
}else{
NSLog(@"Can't report monitoring");
}
}
NSLog(@"delete region");
//delete old region
for (CLRegion *monitor in [locationManager monitoredRegions]){
[locationManager stopMonitoringForRegion:monitor];
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{
for (CLRegion *monitor in [locationManager monitoredRegions]){
}
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(@"entered region, %f, %f",region.center.latitude, region.center.longitude);
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Arrived!" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
[locationManager stopMonitoringForRegion:monitor];
}}
{
NSLog(@"fail monitoring, %@", error);
}
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:NO];
//heading
if( [CLLocationManager locationServicesEnabled]
&& [CLLocationManager headingAvailable]) {
[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];
locationManager.headingFilter = 1;
}else {
NSLog(@"Can't report heading");
}
コメント
コメントを投稿