开发者

How to place my own object on map?

开发者 https://www.devze.com 2023-01-28 07:36 出处:网络
I am learnin开发者_Python百科g maps in iphopne i have read a tutorial and successfully added a pin to a specific location ....

I am learnin开发者_Python百科g maps in iphopne i have read a tutorial and successfully added a pin to a specific location ....

How do I show my own picture at the place of the pin?

Please provide some code if possible...

Thank you


- (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;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消