Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS MapKit custom pins

Tags:

ios

mapkit

How do I show images instead of pins in the map. So far I can only add pins on tap. A sample code of the .m would extremely help since i'm still new to iOS programming.

like image 660
Bahamut Avatar asked Aug 22 '11 10:08

Bahamut


People also ask

What is MapKit in iOS?

Overview. Use MapKit to give your app a sense of place with maps and location information. You can use the MapKit framework to: Embed maps directly into your app's windows and views. Add annotations and overlays to a map to call out points of interest.

What is Mkplacemark?

A placemark is a concrete annotation object and conforms to the MKAnnotation protocol. Because it is an annotation, you can add a placemark directly to the map view's list of annotations.

Is MapKit an API?

MapKit is a powerful API available on iOS devices that makes it easy to display maps, mark locations, enhance with custom data and even draw routes or other shapes on top.


2 Answers

#pragma mark -
#pragma mark MKMapView delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
    if(annotationView)
        return annotationView;
    else
    {
        MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                         reuseIdentifier:AnnotationIdentifier] autorelease];
        annotationView.canShowCallout = YES;
        annotationView.image = [UIImage imageNamed:@"someImage.png"];
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];
        annotationView.rightCalloutAccessoryView = rightButton;
        annotationView.canShowCallout = YES;
        annotationView.draggable = YES;
        return annotationView;
    }
    return nil;
 }

EDIT:

I could explain to you all about the MKAnnotationView, but I think you will find the documentation provided by Apple to be a far better explanation than from any other source. Check the overview section in the link.

https://developer.apple.com/documentation/mapkit/mkannotationview

like image 73
Robin Avatar answered Oct 09 '22 17:10

Robin


Go to organizer of Xcode and then go to documentation and search weatherMap it shows example for map with including images at annotation.

like image 38
jbchitaliya Avatar answered Oct 09 '22 16:10

jbchitaliya