- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我不明白为什么调用 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 分钟后,箭头仍然存在......感谢您的帮助!
编辑:
我想我错过了一些非常重要的东西,在应用程序启动后我的第一个 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];
谷歌地图可能一直在更新吗?如果是,我该如何阻止它?
最佳答案
关于谷歌地图:当你推送新的 View Controller 时,你是否关闭了 myLocationEnabled
字段?如果没有,则可以保持 GPS 运行。您可以通过不在下一个 View Controller 上启动 GPS 来尝试。如果 GPS 保持打开状态,那么 map 就在控制它。
旁注:这可以是正常操作的一部分。如果您的应用程序停止接收位置更新,那么您一切正常。 iOS 正在做很多优化,让 GPS 开启一段时间可能是其中的一部分。在测试期间,我发现即使应用程序被 XCode 杀死,箭头通常会保持一段时间。
关于iphone - 调用了 "StopUpdatingLocation"但 GPS 箭头没有消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18490153/
我正在处理 CLLocationManager。我的应用程序正在注册后台“应用程序注册位置更新”。但是当我调用“stopUpdatingLocation”并转到后台时,我的应用程序不再运行(我的应用程
即使我在我的位置管理器上调用了 stopUpdatingLocation,位置管理器图标仍然位于我的 iPhone 的右上角。为什么还没有停止? 最佳答案 即使在调用 stopUpdatingLoca
为了在我的应用程序中节省电量,我决定在应用程序处于事件状态时混合使用 startUpdatingLocation 并在应用程序处于后台时进入 startMonitoringSignificantLoc
当我的应用移至后台时,我调用了以下代码 - [m_coreLocationMan stopUpdatingLocation]; 但是,紫色三角形仍然存在。我是否还需要做其他事情才能成功? 最佳答案 这
我在 CLLocationManager 上调用 startUpdatingLocation(),在 didUpdateLocations 方法中我调用 stopUpdatingLocation()
我在做 map 应用, 我正在尝试使用 [locationManager stopUpdatingLocation]; 方法来停止位置服务。 在iOS4.3上好像还可以,在iOS5上就不行了。 请有人
我不明白为什么调用 stopUpdatingLocation 后灰色 gps 箭头不会消失。这是我的代码: - (void)viewDidLoad { [super viewDidLoad];
问题:我似乎无法阻止 Core Location 向我的应用/跟踪发送更新。 我在做什么:在我的 viewWillAppear 中,我调用了 self.locationManager 并将其传递给一个
我想验证如果我在 CLLocationManager 实例上调用 startMonitoringSignificantLocationChanges 然后调用 stopUpdatingLocation
这是我的场景。在我的应用程序中,不需要持续监控用户位置,但我需要位置尽可能准确。所以我只是调用 CLLocationManager startUpdatingLocation 并将 kCLLocati
我尝试了很多方法来停止我的应用程序的位置更新,但似乎没有任何效果...... 我做什么(关于帖子:StopUpdatingLocation method not working for iOS5):
我有一个 View 有一个 map View 的 subview 。我使用 CLLocationManager 获取当前位置并显示在 map 上。然后当 View 即将关闭时,我执行以下操作 _map
有谁知道为什么某些捆绑标识符与其他捆绑标识符的位置指示器保持不变?我正在使用安装在运行版本 5.0.1 的 iOS 设备上的 Apple 示例 LocateMe 应用程序。当我使用旧的包标识符时,在调
我想知道当 stopUpdatingLocation 被调用或必须一直调用方法 startUpdatingLocation 才能调用它们? 另一件事是开始区域监控的最佳位置 最佳答案 如果您的应用进入
我是一名优秀的程序员,十分优秀!