20

I need to fetch the user current location for the WatchKit App in watchOS 2. How do I do this?

Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
Jyothi
  • 384
  • 1
  • 3
  • 10

1 Answers1

24

The other answers are incorrect. You can request location directly on the watch for watch OS2. The available method is called requestLocation. It allows you to request a single location update.

E.g.

#import <CoreLocation/CoreLocation.h>
@interface className : WKInterfaceController<CLLocationManagerDelegate>

Then where you want to request location:

self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestLocation];

Then you will get a single callback in one of the following CLLocationManagerDelegate methods.

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    // Callback here with single location if location succeeds
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    // Error here if no location can be found
}

See the WWDC15 video "What's New in Core Location" - https://developer.apple.com/videos/wwdc/2015/?id=714

Imgur

danielbeard
  • 9,120
  • 3
  • 44
  • 58
  • 1
    Thanks! But to it's important to mention that this not works in an ExtensionDelegate. In a "WKInterfaceController" it operates perfectly well. – Blank Nov 25 '15 at 16:48
  • @Blankarsch Is there any reason this is the case? What if we need a central manager independent of UI? – TealShift Oct 06 '16 at 21:49