我使用 Parse.com 作为后端,我想在我的地图上显示地理点。每个 Geopoint 还与数据库布尔字段 true 或 false 连接。
如何为“真”地理点显示绿色针脚颜色,为“假”地理点显示红色针脚颜色?
这是MapViewController.m的代码
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
我有一个函数可以对 parse.com 数据库执行查询以返回所有位置数据。它在 viewDidLoad 方法中被调用。
- (void)viewDidLoad
{
[super viewDidLoad];
[self getAllStations];
}
然后我像这样设置annotationView:
#pragma mark - MapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)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;
}
这是MapViewAnnotation.m(对象)的代码:
#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
谁能给我一个提示,我如何根据布尔值显示绿色和红色引脚?
提前致谢!