MapKit mapView:viewForAnnotation对引脚颜色没有影响

时间:2011-10-14 15:31:15

标签: iphone ios mkmapview mapkit

我似乎无法改变引脚颜色。

我的视图控制器扩展<MKMapViewDelegate>并实现mapView:viewForAnnotation我很接近,但必须遗漏一些东西。任何帮助将不胜感激。

MainViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "StopAnnotation.h"

#define METERS_PER_MILE 1609.344

@interface MainViewController : UIViewController <MKMapViewDelegate> {

}
@property (weak, nonatomic) IBOutlet MKMapView *mapView;

@end

MapViewController.m

#import "MainViewController.h"

@implementation MainViewController
@synthesize mapView=_mapView;

- (void)viewWillAppear:(BOOL)animated
{
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = 43.066667;
    zoomLocation.longitude = -89.4;

    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, METERS_PER_MILE, METERS_PER_MILE);

    MKCoordinateRegion adjustRegion = [_mapView regionThatFits:viewRegion];

    [_mapView setRegion:adjustRegion animated:YES];
    [_mapView addAnnotation:[[StopAnnotation alloc] initWithCoordinate:zoomLocation]];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKPinAnnotationView *pav = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
    pav.pinColor = MKPinAnnotationColorPurple;
    return pav;
}

// the rest of the methods are default, i.e. viewDid* and shouldAutorotate*, etc...

StopAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface StopAnnotation : NSObject <MKAnnotation> {
    CLLocationCoordinate2D coordinate;
    NSString *title;
    NSString *subtitle;
}
- (id)initWithCoordinate:(CLLocationCoordinate2D)c;
@end

StopAnnotation.m

#import "StopAnnotation.h"

@implementation StopAnnotation
@synthesize coordinate;

- (NSString *)subtitle {
    return @"subtitle";
}

- (NSString *)title {
    return @"title";
}

- (id)initWithCoordinate:(CLLocationCoordinate2D)c {
    coordinate = c;
    NSLog(@"%f,%f", c.latitude, c.longitude);
    return self;
}

@end

我正在做运动&amp;代码主要来自here

谢谢!

1 个答案:

答案 0 :(得分:2)