How to group or cluster the pin results using a ios map render?
I tried the following logic, but I got confused in the implementation.
https://github.com/xamarin/ios-samples/blob/main/ios11/MapKitSample/Tandm/ViewController.cs
if (e.NewElement != null)
{
var formsMap = (InitMap)e.NewElement;
var nativeMap = Control as MKMapView;
customPins = formsMap.InitCustomPins;
nativeMap.GetViewForAnnotation = GetViewForAnnotation;
nativeMap.CreateClusterAnnotation = GetClusterView();
}
[![protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
MKAnnotationView annotationView = null;
if (annotation is MKUserLocation)
return null;
var customPin = GetCustomPins(annotation as MKPointAnnotation);
//it returns 37 pins . I would like to cluster by item.Id .
if (customPin == null)
{
return null;
}
foreach (var item in customPin)
{
var clusterThis=item.id
if ID==1
{ PAINT THE BUBBLE RED }
int clusterSize = GetClusterSize(); // Obtain the cluster size
MKCreateClusterAnnotation clusterAnnotation =
GetClusterAnnotation(clusterSize); heres what I dont know how to implement .
}
}]

Map marker clustering is a new feature in iOS11. The sample MapKit Sample "Tandm" shows how to implement the new iOS 11 annotation clustering feature.
I made a demo following the New Features in MapKit on iOS 11 and use much code in MapKit Sample "Tandm" as well.
CustomMapRenderer.cs
After we add some pin data, we should add pin annotation to our nativeMap. In order to do it, We define a MyCustomPin model class.
Here is MyCustomPin class. Later we will decide the clusteridendifier according this Id property.
GetViewForAnnotation is the most important method, we customize our pin and cluster in it. CustomMKAnnotationView inherits from MKAnnotationView, which is the visual representation of custom Pin.
CustomMKAnnotationView.cs
ClusteringIdentifier – This controls which markers get clustered together. For example, if the pin id is 45, we set all its annotation view's ClusteringIdentifier to the same value, such as 45. Then they will be clustered.
ClusterView.cs
This class uses for customize the cluster view. We count the number, paint different color for different cluster and draw the text in the circle.
Finally, this is the effect,