Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clustering annotations with Mapbox

Tags:

ios

swift

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

like image 989
kernelpanic Avatar asked Jul 15 '17 20:07

kernelpanic


1 Answers

I did some research on this not too long ago and it didn't seem to be possible on iOS. Here is the suggestion on github that is still open. Here is another issue about how it wasn't mentioned in the documentation but has since been added.

like image 110
keverly Avatar answered Nov 06 '22 00:11

keverly