标签: cllocationmanager

为什么在iPhone SDK 4.0中没有调用CLLocationManager委托?

这是我在AppDelegate类中的代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = 1000;  // 1 Km
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    [locationManager startUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)

这是我在AppDelegate类中的委托方法

    //This is the delegate method for CoreLocation
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{

        //printf("AppDelegate latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude);

}
Run Code Online (Sandbox Code Playgroud)

它工作在3.0,3.1,3.1.3,但它不适用于4.0模拟器和设备.

是什么原因 ?

iphone core-location cllocationmanager cllocation

12
推荐指数
1
解决办法
2万
查看次数

locationServicesEnabled始终返回YES

如果启用了位置服务,我测试了我的设备(iPod Touch 2G iOS 4.1)

permitted = [locationManager locationServicesEnabled];
Run Code Online (Sandbox Code Playgroud)

无论是否启用了位置服务,我总是得到YES.我说的是位置服务的常规按钮,而不是应用程序特定的按钮.在iOS 3.2.2的iPad上一切正常.

iphone cocoa-touch objective-c cllocationmanager

12
推荐指数
3
解决办法
7669
查看次数

CLLocationManager Singleton - 这是要走的路吗?

我正在构建一个具有两个简单视图的应用程序(在tabbar中).

  • 第一个视图:它应显示用户的位置(默认蓝点)并从服务器加载数据.
  • 第二个视图:它应该显示用户的位置(我的自定义引脚带有注释和标注).用户可以点击标注并提交有关当前位置的数据.

我开始使用MKMapView的showsUserLocation.然后我读到最好使用CLLocationManager单例实例,所以我粗略地关注了这篇博文:http://jinru.wordpress.com/2010/08/15/singletons-in-objective-c-an-example-of -cllocationmanager /

现在这几乎可行,但我想知道这是否是正确的做事方式.

此外,我找不到显示默认蓝点而不是自定义引脚的方法.我读过我应该使用MKMapView的showsUserLocation,但是不会创建另一个CLLocationManager实例吗?

谢谢

mkmapview cllocationmanager ios

12
推荐指数
1
解决办法
4151
查看次数

使用startMonitoringForRegion可以监视的最大区域数是多少:region desiredAccuracy:accuracy?

该文件说,可监测的区域数量有限 -

(void)startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy
Run Code Online (Sandbox Code Playgroud)

但我找不到那个限制,有人知道吗?

iphone core-location cllocationmanager ios

12
推荐指数
1
解决办法
4678
查看次数

区域监控当前位置在退出时不通知

我正在尝试测试区域监控,因为我正在获得这样的当前位置:

- (void)startLocationTracking
{
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];

    // Start location manager
    if ([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
        locationManager = [LocationTracker sharedLocationManager];
        locationManager.delegate = self;
        [locationManager startMonitoringSignificantLocationChanges];
    }
}
Run Code Online (Sandbox Code Playgroud)

并跟踪区域监控的第一个位置,如下所示:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:manager.location.coordinate radius:300 identifier:@"first location initializer"];

        NSLog(@"0: %@", manager.location);
        NSLog(@"1: %@", region);

        [manager startMonitoringForRegion:region];
        NSLog(@"[locationManager startMonitoringForRegion:%@];", region);
    });
}
Run Code Online (Sandbox Code Playgroud)

然后在当前区域的每个出口处,我正在监视新位置,如下所示:

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    NSLog(@"%s, %@", __PRETTY_FUNCTION__, region);
} …
Run Code Online (Sandbox Code Playgroud)

objective-c core-location cllocationmanager ios clregion

12
推荐指数
1
解决办法
4420
查看次数

iOS上的标准位置服务电池耗尽

我注意到如果我有一个使用重要位置更改的应用程序,它确实需要大约30%的电池超过24小时.我认为SLC不应该耗尽电池.

这种行为是否正常?我们在iOS 4.3和8.4的iPhone 6上科学地进行了测试.我们还试用了iPhone 5c(iOS 8.3和8.4).

iphone location core-location cllocationmanager ios

12
推荐指数
1
解决办法
584
查看次数

UIAlertView就像"打开位置服务以允许地图确定您的位置".设置+取消

我想发出此警报:

Turn On Location Services to allow maps to determine your location
Run Code Online (Sandbox Code Playgroud)

我需要"设置"和"取消",就像"地图"应用程序一样.

"设置"应该打开设置 - >常规 - >位置服务

我没有找到打开设置页面的方法.

你能帮助我吗?

谢谢

iphone permissions settings uialertview cllocationmanager

11
推荐指数
3
解决办法
2万
查看次数

适用于iOS的漂亮打印距离

我有两个CLLocation对象,我希望以漂亮漂亮的格式显示它们之间的距离.像"22英尺","58码"或"2.3英里"

CLLocation *location1 = [[CLLocation alloc] initWithLatitude:42.333297 longitude:-71.588858];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:42.353297 longitude:-71.578858];

float target = [location1 getDistanceFrom:location2];
Run Code Online (Sandbox Code Playgroud)

基本上,iOS库中有什么东西可以将距离转换为漂亮的字符串,还是我必须手动执行此操作?

iphone objective-c core-location cllocationmanager ios

11
推荐指数
3
解决办法
4523
查看次数

用于过滤无效/不准确位置的iOS位置服务方法

我正在使用我Location Services的一些应用程序.我有一个方法,我在我的locationManager:didUpdateToLocation:fromLocation:方法中用来过滤掉不良,不准确或太远的位置.并尽量减少gps"抖动".这是我使用的:

/**
 * Check if we have a valid location
 *
 * @version $Revision: 0.1
 */
+ (BOOL)isValidLocation:(CLLocation *)newLocation withOldLocation:(CLLocation *)oldLocation {

    // Filter out nil locations
    if (!newLocation) return NO;

    // Filter out points by invalid accuracy
    if (newLocation.horizontalAccuracy < 0) return NO;
    if (newLocation.horizontalAccuracy > 66) return NO;

    // Filter out points by invalid accuracy
    #if !TARGET_IPHONE_SIMULATOR
    if (newLocation.verticalAccuracy < 0) return NO;
    #endif

    // Filter out points that are out of order …
Run Code Online (Sandbox Code Playgroud)

gps objective-c core-location cllocationmanager ios

11
推荐指数
2
解决办法
2823
查看次数

在Today Extension上访问用户的位置

是否可以访问用户在小部件上的位置?

我使用了新的iOS 8 API

[locationManager requestWhenInUseAuthorization];
Run Code Online (Sandbox Code Playgroud)

我在info.plist文件中添加了密钥

NSLocationWhenInUseDescription
Run Code Online (Sandbox Code Playgroud)

但是,当我请求位置访问时,应该会出现警报,但不会发生.

iOS今天的扩展是否有一些未声明的限制?

core-location cllocationmanager ios ios8 ios-app-extension

11
推荐指数
1
解决办法
2085
查看次数