标签: cllocationmanager

didUpdateHeading 未在 swift 中调用

我正在尝试获取设备的航向信息,以便利用磁航向和真实航向之间的差异来确定用户位置的磁偏角。为此,我有一个 Helper 类和我的 MainVc (mvc)。在我的辅助类 init 方法中,我执行以下操作:

...
...
locationManager = CLLocationManager()
switch CLLocationManager.authorizationStatus() {
  case .AuthorizedAlways:
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
    locationManager.startUpdatingLocation()
  case .NotDetermined:
    locationManager.requestAlwaysAuthorization()
  case .AuthorizedWhenInUse, .Restricted, .Denied:
    mvc.alertDenied();
}

if (!initialized)
{
  initialized = true;
  self.performSelector("finishUpdatingLocation", withObject: nil, afterDelay: 2.0);
}

}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    print ("didUpdateLocations")
    var userLocation:CLLocation = locations[0] as! CLLocation
    longitude = Float(userLocation.coordinate.longitude);
    latitude = Float(userLocation.coordinate.latitude);
  }


 func finishUpdatingLocation () {
    locationManager.stopUpdatingLocation();
    NSObject.cancelPreviousPerformRequestsWithTarget(self, selector: "finishUpdatingLocation", object: nil);
    mvc.goingToUpdateHeading();
    locationManager.startUpdatingHeading(); …
Run Code Online (Sandbox Code Playgroud)

cllocationmanager swift ios9

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

iOS 13 在应用程序被终止时跟踪用户位置

即使应用程序被用户杀死,我也想跟踪用户位置。我已经尝试过下面的代码,但在应用程序关闭时不起作用。

override func viewDidLoad() {
        super.viewDidLoad()
        locationManager.delegate = self
         self.checkUsersLocationServicesAuthorization()
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.allowsBackgroundLocationUpdates = true
        locationManager.requestAlwaysAuthorization()
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()

    }


extension ViewController: CLLocationManagerDelegate {

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        for location in locations {

            let objr = ["lat": "\(location.coordinate.latitude)",
                "logn": "\(location.coordinate.longitude)",
                "date": self.getCurrentDateAndTime()]
            self.saveToCoreDataAndFetchBack(objr as NSDictionary)
            //self.TriggerNotification()
        }
    }



}
Run Code Online (Sandbox Code Playgroud)

cllocationmanager ios swift

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

有没有办法将CLLocationManager常量设置为基于里程而不是基于公里?

我试图找到一种方法来改变使用CLLocationManager构建的iphone应用程序,但其设置为千米.有没有办法将它改为里程?

iphone cocoa-touch objective-c cllocationmanager

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

使用UIButton的CLLocationManager startUpdatingLocation

这是我第一次使用CLLocationManager.我不确定我做的是否正确.如果我错了,请纠正我.

我在我的viewDidLoad方法中初始化locationManager 并以相同的方法告诉locationManager startUpdatingLocation.

当代表收到时

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

    [locationManager stopUpdatingLocation];
    //do stuff with the coordinates
}
Run Code Online (Sandbox Code Playgroud)

避免重复调用此委托方法.

我有一个UIButton用户可以点击更新位置的地方

//called by user action
-(IBAction)updateLocation{
    //start updating delegate
    locationManager.delegate=self;
    [locationManager startUpdatingLocation];    
}
Run Code Online (Sandbox Code Playgroud)

但是当位置发生变化时,当我点击时UIbutton,位置坐标根本没有变化.:(

我究竟做错了什么?这是做的权利还是我根本不应该停止locationManager?

帮助将不胜感激.

iphone xcode objective-c cllocationmanager

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

iOS位置服务即使在任务栏中被杀死后仍被应用程序使用

我有一个使用startMonitoringSignificantLocationChanges的应用程序.

打开此项时会出现右上角的紫色箭头.

我正在做一些测试,偶尔我会调用stopMonitoringSignificantLocationChanges.

发生这种情况时,即使我在Xcode中杀死了应用程序,仍会显示紫色箭头.我进入Settings.app - >位置服务,看到我的应用程序旁边的紫色箭头也亮了,这意味着它仍在使用它.这甚至在没有Xcode连接到设备的情况下运行,并且在我从多任务栏中杀死应用程序之后也是如此.

怎么会这样?

不应该杀死应用程序导致重要的位置变更监控停止?

这肯定发生在5.1 ...没有用5.0测试.

core-location cllocationmanager

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

如果在运行时将nil传递给不应接受的参数,会发生什么?

假设我有一个采用CLLocationCoordinate2D的方法.我无法将nil直接传递给代码中的nil; 编译器抱怨.但是,以下编译.那么在运行时会发生什么?

CLLocation* loc = nil;
[self passMeCoordinates:loc.coordinate];
Run Code Online (Sandbox Code Playgroud)

iphone location objective-c cllocationmanager ios

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

在重要位置更改后,应用程序不会使用位置键启动

我的应用程序也在应用程序终止后使用CLLocationManager类中的方法startMonitoringSignificantLocationChanges来使用核心位置.

我的应用程序使用方法中的iOS 5和6中的位置键启动: - (BOOL)应用程序:application didFinishLaunchingWithOptions:launchOptions; 在AppDelegate类中,一切运行良好.

但在iOS-7测试版中,应用程序在重要位置更改后不会使用位置键启动.

有人遇到过这个问题吗?

我在模拟器和设备上试了一下.

谢谢您的帮助.

iphone background objective-c cllocationmanager ios7

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

iBeacon可靠/不可靠

我正在研究我的家庭自动化应用程序.我正在使用estimotes iBeacons,我想要做的就是让我的家庭自动化控制能够知道我在家里的距离.每个iBeacon在我的家庭控制器上都有一个虚拟开关,当我接触到iBeacon时,我的设备在前台或后台将更新我的控制器以打开我的开关,当我靠近灯塔时关闭它然后当我有想远离我的灯塔.所有这一切都很完美,我很喜欢它,但是我的一些条件依赖于我在一段时间内接近,而我注意到的是几分钟后甚至在接近半小时后一个信标,iPhone 5s基本上断开它的连接,然后将其重新启动,导致它执行退出(关闭我的虚拟交换机),然后立即执行输入(转回虚拟交换机).你可以想象这对于妻子和我自己来说非常烦人,因为退出/进入,卧室的灯开始闪烁.我已经读过有关此问题的人,并尝试了我在互联网上看到的一切无济于事.

我注意到,每当为iBeacon划过监视器交叉时,都会调用didDetermineState和相应的Enter/Exit回调函数.我该怎么办才能让它停止发生?如果需要,我可以提供代码示例,但这更像是一个普遍的问题.

iphone objective-c cllocationmanager ibeacon

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

Parse.com让附近的用户

我需要使用我的应用程序获取15个最近用户的列表.当前用户的当前位置存储如下:

PFGeoPoint *currentLocation =  [PFGeoPoint geoPointWithLocation:newLocation];
PFUser *currentUser = [PFUser currentUser];
[currentUser setObject:currentLocation forKey:@"location"];
[currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
     if (!error)
     {
         NSLog(@"Saved Users Location");
     }
 }];
Run Code Online (Sandbox Code Playgroud)

现在我想通过PFQuery检索附近的用户,如下所示:

- (NSArray *)findUsersNearby:(CLLocation *)location
{

PFGeoPoint *currentLocation =  [PFGeoPoint geoPointWithLocation:location];
PFQuery *locationQuery = [PFQuery queryWithClassName:@"User"];

[locationQuery whereKey:@"location" nearGeoPoint:currentLocation withinKilometers:1.0];
locationQuery.limit = 15;
NSArray *nearbyUsers = [locationQuery findObjects];
return nearbyUsers;
}
Run Code Online (Sandbox Code Playgroud)

不幸的是它不起作用.我的阵列似乎没有条目.有人可以为我清理一下,如何正确使用查询?

干杯,大卫

(也发布于:https://www.parse.com/questions/pfquery-to-retrieve-users-nearby)

cllocationmanager ios parse-platform pfquery

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

通知用户每50/100米移动一次iOS

嗨,我想在位置变化50米(不少于此)时呼叫网络服务。我已尝试使用重大更改,但它至少可以运行500米,并且startupdatelocations始终会调用。因此,我如何检测设备是否从该位置移动了50或100米。

在许多stackoverflow问题中,我都使用距离过滤器为50米。但是在移动到50米之前我无法获得设备中的位置更新信息。

这里有一些关于距离过滤器的解释-iPhone的核心位置:距离过滤器如何工作?

cocoa-touch cllocationmanager ios cllocationdistance

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