CLLocationManager responsiveness

后端 未结 3 1923
名媛妹妹
名媛妹妹 2020-12-08 05:36

I have an app that revolves around the device\'s GPS and the information that comes from it. It is important that the location data be accurate and up-to-date. I know that t

3条回答
  •  心在旅途
    2020-12-08 06:26

    In iPhone we can configure location services by two methods -

    1. By using Standard Location Services, that is satellite GPS which provide you more accurate data.
    2. By using Significant Location Changes that uses A-GPS or get location through wi-fi which provide less accurate data.

    We can configure location services by any of these two methods but it depends on what is the requirement of the app. If the app is a navigation app or a location tracking app then we should use Standard Location Services but before using standard services we have in mind that if you want more accurate data then you have to suffer with battery consume more quickly. If the app don't require location update more frequently and also the accuracy doesn't matter a lot then we should Significant Location Changes because it will save a lot of battery consume as compare to Standard Location Service.

    Standard Location Service uses desiredAccuracy and distanceFilter value to determine whether and when to deliver event.

    desiredAccuracy is the parameter where you can define how much accuracy you want from GPS hardware. It uses some pre-defined constants as -

    kCLLocationAccuracyBestForNavigation
    kCLLocationAccuracyBest
    kCLLocationAccuracyNearestTenMeters
    kCLLocationAccuracyHundredMeters
    kCLLocationAccuracyKilometer
    kCLLocationAccuracyThreeKilometers
    

    distanceFilter is the parameter where you have to define distance, means for how much distance gap you want to ask GPS hardware to send a location update.

    In your case you are dealing with the speed parameter, so i guess its something related to navigation. So you should use Standard Location Services. I think you are also doing that but the issue that you are facing is lag between location updates. Here i suggest you to modify your desiredAccuracy and distanceFilter value to this -

    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; [locationManager setDistanceFilter:10.0f];

    by setting values to this you will get location update in less then 1 sec if your are driving.

    One more thing you have to put in your mind that when you get location update you should check its timestamp value to ignore old location updates. Its because when you start locationManager by calling startUpdatingLocation then the first location you get may be your old location. Also you have to check for horizontalAccuracy value because first few location updates that you get are always not accurate and might have accuracy in 1000 or more that you are not looking for. So you have to check its value to ignore inaccurate location updates.

    Note: If you try with different accuracy and different distance filter value then you will be more clear about it how accurate data iPhone GPS hardware return.
    

提交回复
热议问题