如何在地图上放置我自己的对象?

时间:2010-12-06 05:07:16

标签: iphone ios mkmapview

我正在iphopne学习地图我已经阅读了一个教程,并成功地将一个引脚添加到特定位置....

如何在别针的位置显示我自己的照片?

请尽可能提供一些代码......

谢谢

1 个答案:

答案 0 :(得分:1)

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    MKPinAnnotationView *pinView = nil;
    static NSString *defaultPinID = @"CameraAnnotation";
    pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinView == nil )
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
        UIImageView *pinImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 32)];
        UIImage *pinImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"pinImage" ofType:@"png"]];
        pinImageView.image = pinImage;
        [pinImage release];         

        [pinView addSubview:pinImageView];
        [pinImageView release];

        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;

        UIButton* photoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        photoButton.tag = ((PinAnnotationView*)annotation).tag;
        pinView.leftCalloutAccessoryView = photoButton;
        return pinView;
    }
}