如果这些标记超过10000个,我怎么能对它们进行分组?

I have a map, on which I place markers. How could I group these markers when there will be more than 10000 of them? I found examples only with local JSON but I have the latlng from the server in a form:

[
  {
    "name": "hereName",
    "adr": "hereAdress",
    "latlng": [
      44.444444444,
      55.555555555
    ]
  }
]

Code:

private GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
    if (map == null) {
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        map = mapFragment.getMap();
        map.getUiSettings().setZoomControlsEnabled(true);
        map.setMyLocationEnabled(true);
        map.getUiSettings().setMyLocationButtonEnabled(true);

        if (map != null) {
            new MarkerTask().execute();
        }
    }
}

private class MarkerTask extends AsyncTask<Void, Void, String> {
    private static final String SERVICE_URL = http://exm.com/latlng.php";

    @Override
    protected String doInBackground(Void... args) {
        HttpURLConnection conn = null;
        final StringBuilder json = new StringBuilder();
        try {
            // Connect to the web service
            URL url = new URL(SERVICE_URL);
            conn = (HttpURLConnection) url.openConnection();
            InputStreamReader in = new InputStreamReader(conn.getInputStream());

            int read;
            char[] buff = new char[1024];
            while ((read = in.read(buff)) != -1) {
                json.append(buff, 0, read);
            }
        } catch (IOException e) {
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }
        return json.toString();
    }

    @Override
    protected void onPostExecute(String json) {
        try {
            // De-serialize the JSON string into an array of city objects
            JSONArray jsonArray = new JSONArray(json);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObj = jsonArray.getJSONObject(i);

                LatLng latLng = new LatLng(
                        jsonObj.getJSONArray("latlng").getDouble(0),
                        jsonObj.getJSONArray("latlng").getDouble(1)
                );

                // Create a markers
                map.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
                        .title(jsonObj.getString("name"))
                        .snippet(jsonObj.getString("adr"))
                        .position(latLng));
            }
        } catch (JSONException e) {
        }
    }

Use ClusterManager class of Google maps for this. It will show the markers in a cluster instead of showing them differently

My solution

private GoogleMap map;
private ClusterManager<MyItem> mClusterManager;
double lat;
double lng;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
    if (map == null) {
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        map = mapFragment.getMap();
        map.getUiSettings().setZoomControlsEnabled(true);
        map.setMyLocationEnabled(true);
        map.getUiSettings().setMyLocationButtonEnabled(true);

        mClusterManager = new ClusterManager<MyItem>(this, mapFragment.getMap());
        mapFragment.getMap().setOnCameraChangeListener(mClusterManager);
        mapFragment.getMap().setOnMarkerClickListener(mClusterManager);

        if (map != null) {
          new MarkerTask().execute();
        }
    }
}

private class MarkerTask extends AsyncTask<Void, Void, String> {

    private static final String SERVICE_URL = http://exm.com/latlng.php";

    @Override
    protected String doInBackground(Void... args) {
        HttpURLConnection conn = null;
        final StringBuilder json = new StringBuilder();
        try {
            // Connect to the web service
            URL url = new URL(SERVICE_URL);
            conn = (HttpURLConnection) url.openConnection();
            InputStreamReader in = new InputStreamReader(conn.getInputStream());

            int read;
            char[] buff = new char[1024];
            while ((read = in.read(buff)) != -1) {
                json.append(buff, 0, read);
            }
        } catch (IOException e) {
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }
        return json.toString();
    }

    @Override
    protected void onPostExecute(String json) {
        try {
            JSONArray jsonArray = new JSONArray(json);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObj = jsonArray.getJSONObject(i);

                List<MyItem> items = new ArrayList<MyItem>();
                lat = jsonObj.getJSONArray("latlng").getDouble(0);
                lng = jsonObj.getJSONArray("latlng").getDouble(1);

                items.add(new MyItem(lat, lng));
                mClusterManager.addItems(items);
           }
        } catch (JSONException e) {
        }
    }