ios


Track location of iphone and notify if crosses certain kilometeres in ios Objective C


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];
}
self.currentLocation must be an object of CLLocation.
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
CLLocationDistance dist = [self.currentLocation distanceFromLocation:userLocation.location];
if (dist == 1000.0) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"Title" message:[NSString stringWithFormat:#"Message : you moved %.2f", dist] preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// your code on OK click
}]];
[self presentViewController:alert animated:TRUE completion:^{ }];
}
self.currentLocation = userLocation.location;
self.userLocation = userLocation;
}

Related Links

Magical Record Custom Core Data Migration not pulling existing data
Possible to have nested reusable UICollectionViewCells
Issue while using viewDidLayoutSubviews
Best practices to define Xcode Preprocessor Macros for Multi Projects WorkSpace in iOS
Unable to set top margin NSLayout Constraint programatically in iOS?
iOS Universal link not working
Call a function of an another class (protocol)
Objective C ternary operator vs if statements nil check
Login error in iOS 9 Facebook SDK
How to map each Pixel to Vertex effectively with OpenGL ES on iOS?
how can i make a pop up menu in sprite kit swift? [closed]
Spritekit - Increase duration every 10 points
Allowing user to input nil values with Swift optionals
iOS Developer and Distribution certificate expiring while app in Test Flight
change color uipagecontroller
Magento API with iOS application and Oauth 1.0 Login

Categories

HOME
flutter
opencv
sqlite
dicom
serial-port
runnable
path
genetic-algorithm
twitter-digits
gluu
windows-server-2012-r2
netbeans-8
base
research
xorg
librsvg
openui5
python-2.5
pywin32
javers
powershell-v2.0
deadbolt
ormlite-servicestack
burp
slf4j
epicorerp
point-cloud-library
phonegap-desktop-app
laravel-valet
reformatting
udid
stomp
seh
dashboard-designer
tweenmax
lifecycle
aem-6
rhel7
delete-row
data-science
draggable
confirm
docker-image
caldroid
subscription
btle
polymer-cli
stateful
angularjs-routing
free-diameter
distributed-lock
gulp-babel
paypal-webhooks
jce
waf
error-correction
android-chips
ckcontainer
ellipsis
activity-diagram
hyperterm
bash-completion
asp.net-webpages
mtp
esky
perfview
realm-list
wss4j
bonfire
stringr
epplus-4
twitter-follow
scribe
puppet-enterprise
gcovr
excel-charts
cvs2git
mui
monk
xsltforms
acts-as-taggable-on
pydatalog
django-endless-pagination
freemind
libnids
visual-assist
sparc
chromeless
neventstore
rpn
working-directory
jsr223
ribbon-control
xml-dtd
quilt
postgresql-8.1
boost-gil
coolstorage
wiki-markup
non-relational-database
run-length-encoding
sharepoint-feature
code-statistics

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App