• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - "StopUpdatingLocation"被调用但 GPS 箭头不消失

[复制链接]
菜鸟教程小白 发表于 2022-12-12 13:53:33 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我不明白为什么在调用 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) locationManagerCLLocationManager *)manager didUpdateToLocation:  (CLLocation *)newLocation fromLocationCLLocation *)oldLocation
    {
    NSLog(@"Core location has a position.");

    CLLocationCoordinate2D coordinate = [newLocation coordinate];

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

    [self.locationManager stopUpdatingLocation];

    }

- (void) locationManagerCLLocationManager *)manager
    didFailWithErrorNSError *)error
{

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

我还检查了是否有其他应用正在使用 GPS! 20分钟后,箭头仍然存在...... 感谢您的帮助!

编辑:

我想我错过了一些非常重要的事情,在应用程序启动后我的第一个 View 中有一个谷歌地图!这是我的代码:

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

谷歌地图有没有可能一直在更新?如果是,我该如何阻止?



Best Answer-推荐答案


关于谷歌地图:当你推送新的 View Controller 时,你是否关闭了 myLocationEnabled 字段?如果没有,那么这可以保持 GPS 运行。您可以通过不在下一个 View Controller 上启动 GPS 来尝试。如果 GPS 保持开启状态,则说明 map 正在保持它。

旁注:这可能是正常操作的一部分。如果您的应用程序停止接收位置更新,那么您做得很好。 iOS 做了很多优化,让 GPS 开启一段时间可能就是其中的一部分。在测试过程中,我看到即使应用程序被 XCode 杀死,箭头通常也会保持一段时间。

关于iphone - "StopUpdatingLocation"被调用但 GPS 箭头不消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18490153/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap