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

风流意气都作罢 提交于 2020-01-05 06:02:51

问题


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.


回答1:


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:



来源:https://stackoverflow.com/questions/27636029/show-custom-and-default-callout-views-on-different-pins-with-pin-clustering-on-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!