CLLocation class -1的课程值始终为。为什么?

时间:2013-09-09 05:39:32

标签: iphone ios mapkit core-location

我想在用户移动的方向上显示汽车/自行车,因为我已经使用了课程属性,但它的值始终为-1。以下是特定位置的NSLog值:

2013-09-09 11:05:09.930 MapApp [143:907]< + 23.05910024,+ 72.53762685> +/- 65.00m(速度-1.00 mps / course -1.00)@ 09/09/13 11:05:00 AM印度标准时间

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationViewID";

    annotationView = (MKAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }
    annotationView.image = [UIImage imageNamed:@"Bike.png"];


    NSLog(@"%@",currentLocation);


    annotationView.transform = CGAffineTransformMakeRotation(45);

    return annotationView;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    if (newLocation.horizontalAccuracy < 0)
        return;
    if  (!newLocation)
        return;


    currentLocation = newLocation;
    previousLocation = oldLocation;
    if(currentLocation != nil)
    {
        if (myAnnotation)
        {
            [self.myMapView removeAnnotation:myAnnotation];
        }
        CLLocationCoordinate2D location = CLLocationCoordinate2DMake(currentLocation.coordinate.latitude, currentLocation.coordinate.longitude);
        myAnnotation = [[MyAnnotation alloc] initWithCoordinates:location title:@"Current Location" subTitle:nil];
        [self.myMapView addAnnotation:myAnnotation];
    }
}

1 个答案:

答案 0 :(得分:0)

请参阅此处的文档:

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/GettingHeadings/GettingHeadings.html#//apple_ref/doc/uid/TP40009497-CH5-SW1

获取设备的标题或过程并非易事,但我认为最可能的原因是你没有将应用程序所需的设备功能设置为包括GPS或磁力计。设备可以决定不计算以节省电力。值得考虑的是你是否真的需要这个作为严格的要求。