调用“StopUpdatingLocation”但GPS箭头不会消失

时间:2013-08-28 14:01:16

标签: iphone ios objective-c gps cllocationmanager

我不明白为什么调用stopUpdatingLocation后灰色gps箭头不会消失。这是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.
    if (self.locationManager == nil)
    {
    self.locationManager = [[[CLLocationManager alloc] init]autorelease];
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.delegate = self;
    }
    CLLocation *location = [self.locationManager location];
    CLLocationCoordinate2D coordinate = [location coordinate];

    g_lat = coordinate.latitude;
    g_lng = coordinate.longitude;


    [self.locationManager startUpdatingLocation];
    }

这是我的didUpdateLocation:

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:  (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
    NSLog(@"Core location has a position.");

    CLLocationCoordinate2D coordinate = [newLocation coordinate];

    global_lat = coordinate.latitude;
    global_lng = coordinate.longitude;

    [self.locationManager stopUpdatingLocation];

    }

- (void) locationManager:(CLLocationManager *)manager
    didFailWithError:(NSError *)error
{

    NSLog(@"Core location can't get a fix.");
}

我还检查过是否有其他应用使用GPS! 20分钟后,箭仍然在那里...... 谢谢你的帮助!

修改

我想我错过了一些非常重要的东西,在App开始后的第一个视图中有一个Google Map!这是我的代码:

  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:g_lat
                                                            longitude:g_lng
                                                                 zoom:15];



    self.mapView = [GMSMapView mapWithFrame:CGRectMake(1.0f, 160.0f, 320.0f, 100)
                                     camera:camera];

    self.mapView.delegate = self;
    self.showsUserLocation = YES;
    self.mapView.trafficEnabled = YES;
    self.mapView.myLocationEnabled = YES;
    self.mapView.settings.myLocationButton = YES;
    self.mapView.settings.compassButton = YES;
    [self.mapView setUserInteractionEnabled:YES];
    [self.mapView setCamera:camera];

    [self.containerView addSubview:self.mapView];

谷歌地图是否有可能一直在更新?如果是,我怎么能阻止它?

1 个答案:

答案 0 :(得分:1)

关于谷歌地图:当您按下新的视图控制器时,是否关闭了myLocationEnabled字段?如果没有,则可以保持GPS运行。您可以通过不在下一个视图控制器上启动GPS来尝试它。如果GPS保持打开状态,那么地图就会按住它。

旁注:这可以是正常操作的一部分。如果您的应用停止接收位置更新,那么您做得很好。 iOS正在进行大量优化,并且将GPS保持一段时间可能是其中的一部分。在测试期间,我看到箭头通常会保持一段时间,即使应用程序被XCode杀死。