Map clustering - max zoom markers still clustered

前端 未结 3 1648
花落未央
花落未央 2021-01-19 03:27

I\'m using android maps utils for clustering the markers on google maps api v2. It worked fine, but when I added 2000+ markers, on max zoom it is still clustered (markers st

3条回答
  •  半阙折子戏
    2021-01-19 04:25

    To filter markers that have the same position, you could simply use a hashmasp, whose key is computed from the marker coordinates.

    Something like:

    Map uniqueMarkers = new HashMap();
    for (Markers m : allMarkers) {
      // Compute a key to filter duplicates
      // You may need to account for small floating point precision errors by 
      // rounding those coordinates
      String key = m.getLatitude() + "|" + m.getLongitude();
    
      if (uniqueMarkers.get(key)!=null ) {
        // Skip if we have a marker with the same coordinates
        continue;
      }
    
      // Add marker and do something with it  
      uniqueMarkers.add(key, m);
    
      // ...
    }
    

提交回复
热议问题