我知道我们可以在AppleWatchKit代码中使用CoreLocation API。但是,从文档中我还是看到,提取位置只能在父应用程序中完成,而不能在手表应用程序中完成。这是执行此操作的标准方法?
我的要求很简单。我需要显示用户位置的注释。
答案 0 :(得分:0)
在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];
设置这样的注释:
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)];
这里,“map”是watchkit地图的对象。