【问题标题】:Course value of CLLocation class -1 all the time. Why?CLLocation 类的课程值一直为 -1。为什么?
【发布时间】:2013-09-09 05:39:31
【问题描述】:

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

2013-09-09 11:05:09.930 MapApp[143:907] +/- 65.00m(速度 -1.00 mps / 路线 -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];
    }
}

【问题讨论】:

  • 您必须移动才能从 GPS 获取路线和速度读数。这不是磁力计的指南针方向。

标签: iphone ios mapkit core-location


【解决方案1】:

请参阅此处的文档:

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

获取设备的航向或路线并非易事,但我能想到的最可能的原因是 -1 是您没有设置应用程序所需的设备功能以包括 GPS 或磁力计。设备可以决定不计算任何一个以节省电力。值得考虑的是您是否真的需要将此作为严格要求。

【讨论】:

  • 我已将所需设备能力标志设置为磁力计,但此问题仍未解决。
  • 大卫,你能建议另一种解决方案吗?
猜你喜欢
  • 1970-01-01
  • 2019-06-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-28
  • 1970-01-01
  • 2020-09-25
  • 1970-01-01
  • 2014-01-19
相关资源
最近更新 更多