0

I know that we can use the CoreLocation API in the AppleWatchKit code itself. But still, from the documentation, I read that the fetching of locations should be done only in the parent app and not in the watch app. Which is the standard way for doing this?

My requirement is simple. I need to show an annotation for the user location.

Pang
  • 9,564
  • 146
  • 81
  • 122

1 Answers1

0

Get location like this in Apple Watch:

CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
location = [locationManager location];
coordinate = [location coordinate];
latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];

Set annotation like this:

CLLocationCoordinate2D mapLocation = CLLocationCoordinate2DMake([lati floatValue], [longi floatValue]);

MKCoordinateSpan coordinateSpan = MKCoordinateSpanMake(1, 1);

[self.map setRegion:(MKCoordinateRegionMake(mapLocation, coordinateSpan))];

//For coloured pin 
//[self.map addAnnotation:mapLocation withPinColor: WKInterfaceMapPinColorGreen];
[self.map addAnnotation:mapLocation withImage:[UIImage imageNamed:@"mapPin.png"] centerOffset:CGPointMake(0,-7)];

Here, "map" is the object of watchkit map.

Pang
  • 9,564
  • 146
  • 81
  • 122
iOSNoob
  • 1,420
  • 2
  • 16
  • 30
  • Can we do this in apple watch itself. I learnt in the documentation that getting the locations should be done in the host app. [Documentation](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/iOSSupport.html#//apple_ref/doc/uid/TP40014969-CH21-SW1). Thanks for your help. – Vignesh Ravichandran Jul 27 '15 at 17:40
  • Even if you do this in watchkit app extension classes then it will return you the locations of device only i.e iphone. – iOSNoob Jul 28 '15 at 07:29