title: Map Annotations ars displaying with incorrect custom pin images
body: <p>This is my first question on this site. </p>
  
  <p>My code is implemented in the following function using iOS 6 Mapkit, Objective-C.</p>
  
  <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation 
  </code></pre>
  
  <p>I have ONLY TWO annotations with custom pin images. One red pin and the other a orange pin. The red pin is closer to the user's current location within device map area and the other orange pin is 30 miles away (outside current map context). I am using different colors based on the data behind each pin.  </p>
  
  <p>Problem: Custom images for annotations are switching images.</p>
  
  <p>Using all the tips on this site which includes usage of dequeueReusableAnnotationViewWithIdentifier, etc attached is my code.</p>
  
  <p>On the very first display of the map on app launch, the error I see is that the orange pin displays on the device map and the red one is displayed outside. This is incorrect because the red image should have displayed on the device map. </p>
  
  <h2>If I tap the 'Find Me' button on the map to refresh my current location the red pin displays on the map which is now correct. When I tap 'Find Me' again, the red pin switches out to orange pin-- and it keeps switching or toggling pin image colors.</h2>
  
  <pre><code>if (PinColor == 0) {
              MKAnnotationView* pinview = (MKAnnotationView *)[self._mapView dequeueReusableAnnotationViewWithIdentifier:@"identifier"];
  
              if (nil == pinview) {                    
  
                  MKAnnotationView* view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"identifier"];
  
              view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  
              view.opaque = YES;
              view.image = [UIImage imageNamed:@"redpin.png"];
  
              [view setCanShowCallout:YES];                
  
              if (self.newPinAdded) {
                  [view setSelected: YES];                    
              }
  
              return view;
          }
  
          return pinview;            
      }
      else {
  
          MKAnnotationView* pinview = (MKAnnotationView *)[self._mapView dequeueReusableAnnotationViewWithIdentifier:@"Orangeidentifier"];
  
          if (nil == pinview) {                
  
              MKAnnotationView* view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Orangeidentifier"];
  
              view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  
              view.image = [UIImage imageNamed:@"pin glabensmall.png"]; //orange pin
  
              view.opaque = YES;
              [view setCanShowCallout:YES];
  
  
              if (self.newPinAdded) {
                  [view setSelected: YES];                    
              }
  
              return view;
          }
  
          return pinview;
      }
  </code></pre>