首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用MKMapViewDelegate

使用MKMapViewDelegate
EN

Stack Overflow用户
提问于 2012-08-21 18:37:32
回答 1查看 834关注 0票数 0

我不明白为什么它不起作用。

我有一张带有标记的地图,我想更改图标

map.h:

代码语言:javascript
复制
#define METERS_PER_MILE 1609.344

@interface Map : UIViewController<CLLocationManagerDelegate,MKMapViewDelegate>{

IBOutlet MKMapView *map;
CLLocationManager *locationManager;
}


@property(nonatomic,retain) IBOutlet MKMapView *map;
@property(nonatomic,retain)IBOutlet UIWindow *window;
@property (nonatomic, readwrite) CLLocationCoordinate2D location;


- (void)setMarkers:(MKMapView *)mv;
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;

@end

在map.m中是这样的:

代码语言:javascript
复制
@implementation Map

@synthesize map, window, location;


- (void)setMarkers:(MKMapView *)mv 
{
 //no necesary here

}


- (void)viewWillAppear:(BOOL)animated {
// 1
location.latitude = 38.989567;
location.longitude= -1.856283;
// 2
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location, 0.8*METERS_PER_MILE, 0.8*METERS_PER_MILE);
// 3
MKCoordinateRegion adjustedRegion = [map regionThatFits:viewRegion];
// 4
[map setRegion:adjustedRegion animated:YES];

//[self setMarkers: map];

CLLocationCoordinate2D pointCoord = location;
NSString *theTitle = @"title";
NSString *theSubtitle = @"subtitle";

MapPoint *mp = [[MapPoint alloc] initWithCoordinate:pointCoord title:theTitle subTitle:theSubtitle];
[map addAnnotation:mp];


}

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

   NSLog(@"here!!");
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[MapPoint class]]) {

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (annotationView == nil) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
    } else {
        annotationView.annotation = annotation;
    }

    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;
    annotationView.image=[UIImage imageNamed:@"Icon.png"];//here we use a nice image instead of the default pins

    return annotationView;
}

return nil;
}

@end

永远不会执行viewForAnnotation (我用NSLog检查了这一点)

我该怎么办?

提前谢谢你

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-21 20:49:28

看起来你的代码没有问题。正如phix23所说,您可能没有将MKMapView与委托联系起来:

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12053111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档