Saturday 23 February 2019

Clustering annotations with Mapbox

I'm trying to implement clustering in Mapbox for iOS and literally using this example from Mapbox website

It works fine, but I'd like to be able to use simple MGLAnnotations to place on the map and cluster them together if they are too close.

I read here that MGLShapeSource not only accepts external geoJSON, but other sources, such as polylines and annotations. But when I feed it with annotations array no clustering occur, I just see bunch of my markers from my annotations array:

let source = MGLShapeSource(identifier: "clusteredParkings", shapes: annotationsArray, options: [.clustered: true, .clusterRadius: 20])

When I swap the source back to geoJSON everything works again for clusters. Btw there are no errors or warnings.

What am I doing wrong? Does anyone have a working example of Mapbox clustering with MGLAnnotations rather than geoJSON source file?

https://www.mapbox.com/ios-sdk/api/3.6.0/Classes/MGLShapeSource.html



from Clustering annotations with Mapbox

No comments:

Post a Comment