如何在Apple Watch中集成Apple地图?

时间:2015-04-03 11:29:49

标签: ios iphone watchkit apple-watch

我是Apple Watch开发的新手,想要在Apple Watch中集成苹果地图,只想显示我当前的位置,但每次我在模拟器中加载界面时都会得到如下屏幕。任何帮助都可以升值。

enter image description here

   -(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];
    }

}

2 个答案:

答案 0 :(得分:4)

请点击此链接https://trymakedo.wordpress.com/tag/wkinterfacemap/

检查你获得当前位置坐标的天气你传递给region.Test给出预定义的坐标..

答案 1 :(得分:1)

我自己就试过了,这里有很多陷阱。

我攻击了一个你可以在这里找到的演示项目: https://github.com/sticksen/WatchKit-Map-Sample-Project

清单:

  • 请务必请求位置服务授权,并在用户授予访问权限后开始更新位置
  • 如果已授予授权,您可以立即开始更新位置

现在是最糟糕的部分:

  • 您的主要目标(不是WatchKit目标,只是为了说清楚!)Info.plist必须有一个名为NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription的密钥(取决于什么您请求的授权)作为值具有描述字符串,您希望使用位置服务。如果没有在Info.plist 中设置此键,则无法使用