title: iOS Core Location - Get MOST Accurate Location Coordinates
body: <p>On an app I am working on I need to track the a user's journey, and then map it to the user. In this scenario I need the most accurate location data possible.</p>
  
  <p>I have created a <code>CLLocationManager</code> for this task.
  In order to revive the most accurate location possible I set the desired accuracy filter of the manager to <code>kCLLocationAccuracyBest.</code>
  In order to ensure I don't get extra coordinates when the user is not moving, I set the distance filter the manager to <code>2.5 meters</code>.</p>
  
  <p>However, I was still felt like I would probably get some inaccurate coordinates, so in my <code>-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray&lt;CLLocation *&gt; *)locations</code> delegate method, I set up a filter that uses the estimated horizontal and vertical accuracy of each coordinate to determine whether or not it should be kept or not, and if the coordinate meets the criteria it is stored an an array.</p>
  
  <p>Here is my implementation:</p>
  
  <pre><code>-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray&lt;CLLocation *&gt; *)locations {
      for (CLLocation *loc in locations) {
           if (loc.horizontalAccuracy &gt; -1 &amp;&amp; loc.horizontalAccuracy &lt;= 10 &amp;&amp; loc.verticalAccuracy &gt; -1 &amp;&amp; loc.verticalAccuracy &lt;= 30){
           [self.locationArray addObject:loc];
      }
  }
  </code></pre>
  
  <p>Most of the time, this works pretty well. Requiring a horizontal accuracy of 10 meters and a vertical accuracy of 30 meters seems to be about the best location information the location manager can give me consistently. It ensures the coordinates are an accurate representation of the user's journey. However, in my testing, sometimes the location manager is unable to meet this criteria. This results in a large gap between coordinate points.</p>
  
  <p>A possible solution to this problem would be to loosen the criteria of my filter. However this is problematic because it would result in my keeping inaccurate points when more accurate ones are available.</p>
  
  <p>Another possible solution would be to collect locations for an interval (ex. 30 seconds), then go through them and find the best one. However the problem with this is that in my app the user will probably be moving, possibly at high speeds. The user's location could change significantly in 30 seconds. </p>
  
  <p>I feel like there is a more elegant way to ensure that the coordinates saved have the best accuracy available, but my knowledge of Core Location is limited and I can't seem to find a better solution.</p>
  
  <p>What would be the best way to solve this problem?</p>