title: Comparing two instances of CLLocationDistance to fid the smaller one
body: <p>Hi I have an array of mapAnnotations in my app. Each annotation object has an address and a coordinate. I am using my location manager to find out the user's current location which is a CLLocationDistance object. Then I am trying to iterate over the mapAnnotations array and comparing the user's location with the location coordinates of each annotation to find the one thats closes to the user. 
  Here is the code:</p>
  
  <pre><code>-(void)locationManager:(CLLocationManager*)_manager 
      didUpdateToLocation:(CLLocation *)newLocation 
      fromLocation:(CLLocation *)oldLocation
  {
      self.userLocation = newLocation;
      NSLog(@"Usser location is: %@", self.userLocation);
      NSLog(@"USer location latitude = %.4f", self.userLocation.coordinate.latitude );
      NSLog(@"USer location longitude = %.4f", self.userLocation.coordinate.longitude);
      if (self.userLocation)
      {
          [self.locMgr stopUpdatingLocation];
      }
      [self calculateShortestDistanceBetweenUserAndBiz:self.userLocation];
  }
  
  //==============================================================================
  -(void)calculateShortestDistanceBetweenUserAndBiz:(CLLocation *)_userLocation
  {
      NSLog(@"Entering %s", __FUNCTION__);
      for(LocationMapAnnotation *tempAnnot in self.mapAnnotations)
      {
          CLLocation *tempLocation = [[CLLocation alloc] initWithLatitude:tempAnnot.coordinate.latitude longitude:tempAnnot.coordinate.longitude];
          NSLog(@"tempLocation created %@ ", tempLocation);
          CLLocationDistance tempDistance = [_userLocation distanceFromLocation: tempLocation];
          NSLog(@"tempDistance  was calculated at %d", tempDistance);
          if(!self.shortestDistance) 
          {
              self.shortestDistance = tempDistance;
              NSLog(@"Assigned value %d to shortestDistance", self.shortestDistance);
              continue;
          }
          if(self.shortestDistance &gt;= tempDistance)
          {
          NSLog(@"Replacing shortest distance value from %d to %d", self.shortestDistance, tempDistance);
              self.shortestDistance = tempDistance;
          }
      }
  }
  </code></pre>
  
  <p>The method works fine and here is the console output:</p>
  
  <pre><code>Created a new locationmodel
  
  Usser location is: &lt;+43.47878384, -80.53074371&gt; +/- 1629.00m (speed -1.00 mps / course -1.00) @ 11-05-22 8:58:10 PM Eastern Daylight Time
  
  USer location latitude = 43.4788
  
  USer location longitude = -80.5307
  
  Entering -[locationModel calculateShortestDistanceBetweenUserAndBiz:]
  
  tempLocation created &lt;+43.69445000, -79.75080000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) 
  
  tempDistance  was calculated at 629486151
  
  Assigned value 629486151 to shortestDistance
  
  tempLocation created &lt;+43.62192000, -79.52238000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) 
  
  tempDistance  was calculated at 209234637
  tempLocation created &lt;+43.59233000, -79.54258000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) 
  
  tempDistance  was calculated at -1442027836
  tempLocation created &lt;+43.57980000, -79.61713000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) 
  
  tempDistance  was calculated at -680604989
  
  tempLocation created &lt;+43.55260000, -79.58553000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) 
  
  tempDistance  was calculated at -1882725832
  tempLocation created &lt;+43.58191000, -79.71417000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) 
  
  tempDistance  was calculated at 947780311
  
  Replacing shortest distance value from 629486151 to 1089496493
  
  tempLocation created &lt;+43.65530000, -79.41298000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) 
  
  tempDistance  was calculated at 1561068529
  
  tempLocation created &lt;+43.64854000, -79.38776000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) 
  tempDistance  was calculated at 466814513
  
  tempLocation created &lt;+43.47690000, -80.52500000&gt; +/- 0.00m (speed -1.00 mps / course -1.00) 
  tempDistance  was calculated at -1816387020
  Replacing shortest distance value from 947780311 to 1089489801
  Received memory warning. Level=1
  </code></pre>
  
  <p>My question is now that the function is working, Im trying to understand what the values mean? For instance the values assigned to shortest distance and tempdistance are huge numbers but what do they represent? How do I know the function is working fine. I dont understand. I want to be able to use this value of shortest distance to set my my MKMapview here, I wont to replace the line below with the value which corresponds to the shortest distance from the cetercoord which is the user's location</p>
  
  <pre><code>MKCoordinateRegion preRegion = MKCoordinateRegionMakeWithDistance(centerCoord, 15000, 15000); 
  </code></pre>
  
  <p>Please help.</p>