You can use CoreLocation in the extension of your watch application just as you use it in your iPhone application. The main difference is that the user cannot allow your extension to have access to Core Location. They will need to do this from your iPhone application. Therefore, you will need to check whether the user has authorized location services for your application, and if not, you will need to instruct them on how to do this.
Here is the code I'm using in my watch extension to track my current location. ( GPWatchAlertView is a custom controller that I made to display warning messages.)
#pragma mark - CLLocation Manager -(void)startTrackingCurrentLocation:(BOOL)forTrip { if (self.locationManager == nil) { self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; self.locationManager.activityType = CLActivityTypeFitness; self.locationManager.distanceFilter = 5; //Require 15 meters of movement before we show an update } CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) { NSLog(@"%@ Start tracking current location", self); self.trackingCurrentLocation = YES; self.gpsTrackingForTrip = forTrip; //We wait until we have a GPS point before we start showing it self.showCurrentLocation = NO; [self.locationManager startUpdatingLocation]; } else { [self presentControllerWithName:@"GPWatchAlertView" context:@"Unauthorized GPS Access. Please open Topo Maps+ on your iPhone and tap on current location."]; } } -(void)stopTrackingCurrentLocation:(id)sender { NSLog(@"%@ Stop tracking current location", self); self.trackingCurrentLocation = NO; [self.locationManager stopUpdatingLocation]; self.showCurrentLocation = NO; } -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation* loc = [locations lastObject]; ... }
source share