I need to fetch the user current location for the WatchKit App in watchOS 2. How do I do this?
Asked
Active
Viewed 3,865 times
20

Nate Barbettini
- 51,256
- 26
- 134
- 147

Jyothi
- 384
- 1
- 3
- 10
-
3Why would this question be down voted? It is a perfectly valid question. smh – Rickster Aug 16 '15 at 18:44
1 Answers
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

danielbeard
- 9,120
- 3
- 44
- 58
-
1Thanks! 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