iOS位置问题-无法看到任何数据传入
我不熟悉iOS编程,正在尝试获取当前位置。我的主要应用程序代理是这样的iOS位置问题-无法看到任何数据传入,ios,objective-c,core-location,Ios,Objective C,Core Location,我不熟悉iOS编程,正在尝试获取当前位置。我的主要应用程序代理是这样的 #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @class AWSViewController; @interface AWSAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate> @property (str
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@class AWSViewController;
@interface AWSAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) AWSViewController *viewController;
@property (strong, nonatomic) UINavigationController *navController;
@property (strong, nonatomic) NSMutableArray *cities;
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
@end
我做错了什么?
谢谢您的位置管理器启用了吗?检查它:
if(locationManager.locationServicesEnabled == NO){
//go to settings>location services
}
如果情况不好,方法
locationManager:didFailWithError:
被称为而不是
locationManager:didUpdateLocations
因此,请实施它:
- (void)locationManager: (CLLocationManager *)manager didFailWithError: (NSError *)error {
NSLog(@"error%@",error);
}
是否启用了位置管理器?检查它:
if(locationManager.locationServicesEnabled == NO){
//go to settings>location services
}
如果情况不好,方法
locationManager:didFailWithError:
被称为而不是
locationManager:didUpdateLocations
因此,请实施它:
- (void)locationManager: (CLLocationManager *)manager didFailWithError: (NSError *)error {
NSLog(@"error%@",error);
}
我把它修好了:D
我的locationManager对象-我实例化了它,但您没有保留它,因此它会立即消失在一股烟雾中
@property (strong, nonatomic) CLLocationManager *locationManager;
那么
现在它工作得很好:D我修好了:D
我的locationManager对象-我实例化了它,但您没有保留它,因此它会立即消失在一股烟雾中
@property (strong, nonatomic) CLLocationManager *locationManager;
那么
现在它工作得很好:D一旦代码退出getCurrentLocation方法,位置管理器就会超出范围。制作一个位置管理器ivar,使其保持不变
@interface AWSAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
-(void)getCurrentLocation {
locationManager = [[CLLocationManager alloc] init];
// etc
}
一旦代码退出getCurrentLocation方法,位置管理器就会超出范围。制作一个位置管理器ivar,使其保持不变
@interface AWSAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
-(void)getCurrentLocation {
locationManager = [[CLLocationManager alloc] init];
// etc
}
您的距离过滤器设置为500米。因此,仅当移动>500米时,它才会调用didUpdateLocations。编辑:另外,您最好实现-void didUpdateLocation:CLLocation*loc委托。我已将其设置为5m,但仍然没有设置:您的距离过滤器设置为500m。因此,仅当移动>500米时,它才会调用didUpdateLocations。编辑:另外,您最好实现-void didUpdateLocation:CLLocation*loc委托。我已将其设置为5m,但仍然没有:我已经实现了它,但仍然没有任何东西通过控制台。。您告诉@Kai您将距离过滤器设置为5米,并且您正在谈论NSLog,因此您的设备在Mac上连接。你确定你的手机水平移动了5米吗?我正在使用模拟器并将其设置为高速公路模式,我设法解决了这个问题:请看下面我们已经实现了它,但控制台上仍然没有任何东西。。您告诉@Kai您将距离过滤器设置为5米,并且您正在谈论NSLog,因此您的设备在Mac上连接。你确定你的手机水平移动了5米吗?我正在使用模拟器并将其设置为高速公路模式,我设法解决了这个问题:请看下面