Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用CLLocationManager的正确方法(启动/停止更新用户位置)_Iphone_Ios_Mkmapview_Cllocationmanager - Fatal编程技术网

Iphone 使用CLLocationManager的正确方法(启动/停止更新用户位置)

Iphone 使用CLLocationManager的正确方法(启动/停止更新用户位置),iphone,ios,mkmapview,cllocationmanager,Iphone,Ios,Mkmapview,Cllocationmanager,我在UIViewController中有一个带有MKMapView的UIView,它仅在用户点击按钮时出现 程序如下: CLLocationManager对象在头文件中声明为私有成员 显示带有MKMapView的ui视图(最初帧在边界之外。在同一viewController中,根据用户的操作移动到视图边界之内) 它被初始化为: locationManager = [[CLLocationManager alloc] init]; locationManager.distanceFilter

我在UIViewController中有一个带有
MKMapView
UIView
,它仅在用户点击按钮时出现

程序如下:

  • CLLocationManager
    对象在
    头文件中声明为私有成员
  • 显示带有
    MKMapView
    ui视图
    (最初帧在边界之外。在同一
    viewController
    中,根据用户的操作移动到视图边界之内)
  • 它被初始化为:

    locationManager = [[CLLocationManager alloc]  init];
    locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 100 m
    [locationManager startUpdatingLocation];
    CLLocation *location = [locationManager location];
    CLLocationCoordinate2D coordinate = [location coordinate];
    
    MKCoordinateSpan span = MKCoordinateSpanMake(0.04, 0.04);
    MKCoordinateRegion region = MKCoordinateRegionMake(coordinate, span);
    mapView.showsUserLocation = YES;
    [mapView setRegion:region animated:YES];
    
  • 使用
    Foursquare API获取附近的位置

现在,当
视图从可见边界中移除时,我希望停止位置锁定。

我用
stopUdatingUserLocation
试过了。我还
发布了
locationManager
,但GPS锁定图标在
状态栏中保持不变。据我所知,连续GPS锁定会耗尽电池电量,我想停止这种情况。我该怎么做呢?

即使没有正式的文档记录,在整个应用程序中只使用一个CLLocationManager也会更好。把它当作一个单例,不要每次都初始化它,它应该能正常工作

即使没有正式的文档记录,在整个应用程序中只使用一个CLLocationManager也会更好。将其视为一个单例,不要每次都初始化它,它应该可以正常工作。iOS 7仍然存在关于MKMapView的漏洞。也许你应该在iOS 6上试用你的解决方案来验证?@Klaas,我还没有迁移到iOS 7/XCode5。“我正在使用iOS-6.1。@米坎托克斯,出于某种原因,你的想法似乎奏效了。你应该把这个作为一个答案,我会接受的。我接受了,我确实认为苹果应该更好地管理这个问题