我是Apple Watch开发的新手,想要在Apple Watch中集成苹果地图,只想显示我当前的位置,但每次我在模拟器中加载界面时都会得到如下屏幕。任何帮助都可以升值。
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation* loc = [locations lastObject];
CLLocationCoordinate2D myLocationCoordinate2D = loc.coordinate;
[self.demoMap setRegion:MKCoordinateRegionMake(myLocationCoordinate2D, MKCoordinateSpanMake(0.0,0.0))];//set map region
[self.demoMap addAnnotation:myLocationCoordinate2D withPinColor:WKInterfaceMapPinColorGreen];// set pin on map
[locationManager stopUpdatingLocation];
}
#pragma mark - CLLocation Manager
-(void)startTrackingCurrentLcoation:(BOOL)forTrip
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager requestAlwaysAuthorization];
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse)
{
NSLog(@"%@ Start tracking current location", self);
[locationManager startUpdatingLocation];
}
}
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusDenied)
{
NSString *message = @"To use background location you must turn on 'Always' in the Location Services Settings";
NSLog(@"%@",message);
}
else if (status == kCLAuthorizationStatusNotDetermined)
{
[locationManager requestAlwaysAuthorization];
}
else
{
[locationManager startUpdatingLocation];
}
}
答案 0 :(得分:4)
请点击此链接https://trymakedo.wordpress.com/tag/wkinterfacemap/。
检查你获得当前位置坐标的天气你传递给region.Test给出预定义的坐标..
答案 1 :(得分:1)
我自己就试过了,这里有很多陷阱。
我攻击了一个你可以在这里找到的演示项目: https://github.com/sticksen/WatchKit-Map-Sample-Project
清单:
现在是最糟糕的部分:
NSLocationWhenInUseUsageDescription
或NSLocationAlwaysUsageDescription
的密钥(取决于什么您请求的授权)作为值具有描述字符串,您希望使用位置服务。如果没有在Info.plist 中设置此键,则无法使用!