Question

I am working on such a project where apps do the following things:

1.Getting user current location. 2. Get local notifications when user enters or nearby the particular locations i provided.

What i have done is:

I have downloaded the regions sample code(apple provided) to find out my current location using IOS corelocation framework.It works fine.here's the code below:

// Create a new region based on the center of the map view.

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(regionsMapView.centerCoordinate.latitude, regionsMapView.centerCoordinate.longitude);
CLRegion *newRegion = [[CLRegion alloc] initCircularRegionWithCenter:coord radius:2.0  identifier:[NSString stringWithFormat:@"%f, %f", regionsMapView.centerCoordinate.latitude, regionsMapView.centerCoordinate.longitude]];

Now, my question is how to add specific regions with latitude& longitude to get notified?

Help is highly appreciated.Anybody knows any example or tutorial.

Was it helpful?

Solution 2

Explore the location-based services provided by the iOS Core Location framework.

here are some good tutorials. It may help you

OTHER TIPS

The SetSDK should help make this super easy, https://cocoapods.org/pods/SetSDK. It allows you to setup notifications for user arrival and departure from locations. It currently learns those locations on the fly, but there is a coming release that includes arbitrary location subscription. Your app will receive a notification and you can execute whatever handler you want from there. It would look something like this,

SetSDK.instance.onArrival(to: .any) { newArrival in
    /* Compare the new location with the one of interest (50m) */
    if newArrival.location.distance(from: placeOfInterest) < 50 {
      /* do your things here */
    }
}

1.Getting user current location.

I have lengthy post and sample codes that I posted on my blog and Github on how to get location for iOS 7.

2. Get local notifications when user enters or nearby the particular locations i provided.

You will have to use startMonitoringForRegion to monitor the region that you created.

CLLocationCoordinate2D regionCentre = CLLocationCoordinate2DMake(latitude, longitude);
CLCircularRegion *region= [[CLCircularRegion alloc] initWithCenter:regionCentre radius:radius identifier:@"Name"];        
[locationManager startMonitoringForRegion:region];

From the locationManager delegate, you will be notified when you enter the region.

-(void)locationManager:(CLLocationManager *)manager 
    didEnterRegion:(CLRegion *)region{
NSString* message = [NSString stringWithFormat:@"Message";        
UIApplicationState state = [[UIApplication sharedApplication] applicationState];

if (state == UIApplicationStateBackground || state == UIApplicationStateInactive)
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate date];
NSTimeZone* timezone = [NSTimeZone defaultTimeZone];
notification.timeZone = timezone;
notification.alertBody = message;
notification.alertAction = @"Show";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top