Search This Blog

Tuesday, 12 February 2013

Custom Marker on MapView-iOS

Hello there,
          So here is a new one, how to place a custom marker on MapView in xcode:

its as simple as table view :

Override this following function in your .m file.Remeber to include MKMapViewDelegate in your .h file.

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
        NSString *identifier = @"marker"; //identifier like we declare in tableview
    annotationV = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
        annotationV = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:identifier];
        annotationV.canShowCallout = YES;
        annotationV.image = [UIImage imageNamed:@"green_mark.png"];//using custom image for marker.
        annotationV.canShowCallout =NO;
        annotationV.rightCalloutAccessoryView =  [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    return annotationV;

Here what i am doing is using an image for marker,plus i am also displaying a banner above the marker for description.I am using "popup.png" image for banner.


No comments:

Post a Comment