How to create custom annotation and callout bubble in iphone? - ios

I want to create a customized annotation and callout bubble on MKMapView. I need to use a customized view rather than default annotation pin and annotaion view(which is limited to show only title and a single line description). When user tap on an annotation, I would like to display more information on the callout bubble.

I passed by this control but I haven't used it:
http://cocoacontrols.com/platforms/ios/controls/custom-callout
I've found some pretty good controls at that site.

Related

iOS: How to offer directions from annotation view?

Basically what I'm wondering is how to offer the user an option to get directions in Maps from an annotation (like that little car icon inside of the annotation that opens up directions)
You can use left/right callout accessory view to add your icon and when you tap on it you can implement your direction logic.

Hiding button in annotation callout Swift

I am wondering how I can hide and show a button in an annotation callout?
I set up my annotation view to have a left and a right button, each doing a separate task. The user can add an annotation by selecting a location from a table or long press.
I want the left button to be accessible and the right button to be hidden when the annotation is added via selection from table and the left button to be hidden the the right button to be accessible when the annotation is added via long press.
I have the buttons in the callout working but I can't figure how how to hide/show them. Any help is much appreciated!
Don't use a generic MapAnnotation object. Create a custom object that conforms to the MKAnnotation protocol and give it an Enum property that has a different value if it's added from your table or from a long press.
In your viewForAnnotation method, cast the annotation object to your custom type and check the property before deciding which callouts to add. (You'll need special-case code for the user location, as always.)

Show custom and default callout views on different pins with pin clustering on map view

This is my first question, and i am new to iOS.
I am implementing pin clustering on map view , which in working fine for one type of pin but my requirement is to cluster different kind of pins with different cluster count on it when zoomed out i.e if one kind of pin shows river details on map view than these pins should cluster together and give a count on it and on other case if other pin is showing details for diversion on map view than these pins should cluster together separately from river pin and give a separate count on it. and this same case is followed for other 4 different kinds of pins.
And i have one more issue , how to implement different callout views for these above different kind of pins on same map view i.e suppose river pin have default callout which includes title,subtitle and accessory button. And on other side for Diversion pin i have my own custom call out view . So now i want is when i tap on river pin than default callout should pop out and when i tap on diversion pin than my own custom callout should pop out.And same for other kind of pins too.
Please help me out . I am working on these issues from last 2 weeks but nothing working out for me. Please help me out i want a solution for these problems badly.
NOTE: The custom callout and default callout should be implemented with pin clustering.
I have created a demo, which will solve your problem about custom call out and default call out.
Answer
will guide you how to create custom call out and add pins for it.
This code contains PinAnnotation which is a subclass of MKAnnotation and acts to show custom call out.
For the default call out view you just have to add MKAnnotation to map and it will show default one.
How ever you can customise it if you want and create another sub class for it.
To test default call out with custom call out view. Download demo project from that answer link or directly from here.
Add below code at the end of viewDidLoad() and run the application.
MKPointAnnotation *pin = [[MKPointAnnotation alloc] init];
pin.coordinate = CLLocationCoordinate2DMake(34.65515f, 133.81951f);
pin.title = #"Default Pin";
[self.mapView addAnnotation:pin];
It will be looks like below:

Annotations, Annotations, Annotations

So `MKAnnotation's. Fun stuff.
My questions:
What's the difference between an annotation's title and its subtitle and how does that affect the visual component of the annotation?
What's the difference between a MKPinAnnotationView and a MKAnnotationView?
Are there different types of map annotations in iOS apart from pins?
Title is main heading of your pin.
The subtitle is actually displaying the address/(common info) of the dropped pin.You can store other deeply information of related to title that is puted on pin.
MKAnnotation is a protocol you need to adopt if you wish to show your object on a MKMapView. The coordinate property tells MKMapView where to place it. title and subtitle properties are optional but if you wish to show a callout view you are expected to implement title at a minimum.
MKAnnotationView visually presents the MKAnnotation on the MKMapView. The image property can be set to determine what to show for the annotation. However you can subclass it and implement drawRect: yourself.
MKPinAnnotationView is a subclass of MKAnnotationView that uses a Pin graphic as the image property. You can set the pin color and drop animation.
Don't forget about the leftCalloutAccessoryView and the rightCalloutAccessoryView properties of MKAnnotationView that can be used to customize the callout view.
The title and subtitle are displayed when a pin is selected on the map. The subtitle simply falls below the title.
MKPinAnnotationView is simply an specialized form of MKAnnotationView that knows how to draw a pin (and a shadow) and also allows setting the pin color. It's the only built-in annotation view with an image, you have to make your own if you want something different (but it's very easy to do).

MKAnnotationView - Callout title or description with multiple lines?

Is it possible to display several lines in title or description/subtitle without writing your own custom annotation view, using i.e. MKPinAnnotationView?
I believe it's not possible.
What you need is to create a custom callout, and layout it the way you want. You can even mimic the native appearance.
This page can help you creating the custom callout: http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/

Resources