Note that there are some explanatory texts on larger screens.

plurals
  1. POMKAnnotationView - Set two different Pin colours
    text
    copied!<p>I'm using Parse.com as a backend and i want to show Geopoints on my map. Every Geopoint is also connected with a database boolean field true or false.</p> <p>How can I show a green pins colour for the "true" gepoint and red pins for the "false" Geopoint?</p> <p>Here is code for the <strong>MapViewController.m</strong></p> <pre><code>@property (weak, nonatomic) IBOutlet MKMapView *mapView; </code></pre> <p>I have a function to perform the query against the parse.com database to return me all location data. It is called within the viewDidLoad Method.</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [self getAllStations]; } </code></pre> <p>Then I set the annotationView like this:</p> <pre><code>#pragma mark - MapViewDelegate - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id&lt;MKAnnotation&gt;)geoPointAnnotation { static NSString *MapViewAnnotationIdentifier = @"Places"; MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:MapViewAnnotationIdentifier]; if (geoPointAnnotation == mapView.userLocation) { return nil; } else { annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:geoPointAnnotation reuseIdentifier:MapViewAnnotationIdentifier]; annotationView.pinColor = MKPinAnnotationColorGreen; annotationView.canShowCallout = YES; annotationView.draggable = YES; annotationView.animatesDrop = YES; } return annotationView; } </code></pre> <p>Here is the Code for the <strong>MapViewAnnotation.m (Object):</strong></p> <pre><code>#import "MapViewAnnotation.h" #import "Parse/Parse.h" @interface MapViewAnnotation () @property (nonatomic, strong) PFObject *object; @end @implementation MapViewAnnotation #pragma mark - Initialization - (id)initWithObject:(PFObject *)aObject { self = [super init]; if (self) { _object = aObject; PFGeoPoint *geoPoint = self.object[@"location"]; [self setGeoPoint:geoPoint]; } return self; } - (void)setGeoPoint:(PFGeoPoint *)geoPoint { _coordinate = CLLocationCoordinate2DMake(geoPoint.latitude, geoPoint.longitude); NSString *streetName = self.object[@"adress"]; _title = [NSString stringWithFormat:@"%@", [_object objectForKey:@"name"]]; [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *currentLocationGeoPoint, NSError *error) { //Get current Location if (!error) { PFGeoPoint *distanceGeoPoint = [_object objectForKey:@"location"]; double distanceDouble = [currentLocationGeoPoint distanceInKilometersTo:distanceGeoPoint]; //NSLog(@"Distance: %.1f",distanceDouble); _subtitle = [NSString stringWithFormat:@"%@ - Distance: %.1f km", streetName, distanceDouble]; } }]; } @end </code></pre> <p>Can anyone give me a hint how I can show green and red pins based on a boolean?</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload