/**
   * Manipulates the map once available. This callback is triggered when the map is ready to be
   * used. This is where we can add markers or lines, add listeners or move the camera. In this
   * case, we just add a marker near Sydney, Australia. If Google Play services is not installed on
   * the device, the user will be prompted to install it inside the SupportMapFragment. This method
   * will only be triggered once the user has installed Google Play services and returned to the
   * app.
   */
  @Override
  public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mClusterManager = new ClusterManager<>(this, mMap);
    mClusterManager.setRenderer(new CaseRenderer());
    mClusterManager.setOnClusterClickListener(this);
    mClusterManager.setOnClusterItemInfoWindowClickListener(this);

    //        mClusterManager.getClusterMarkerCollection().setOnInfoWindowAdapter(new
    // MyCustomAdapterForClusters());
    //        mMap.setInfoWindowAdapter(mClusterManager.getMarkerManager());

    mMap.setOnCameraChangeListener(mClusterManager);
    mMap.setOnMarkerClickListener(mClusterManager);
    mMap.setOnInfoWindowClickListener(mClusterManager);
    mMap.setOnCameraChangeListener(mClusterManager);

    try {
      cases = readMapData();
      Log.d("Heath", "cases size:" + cases.size());
      float average_unit_price = getAverageUnitPrice(cases);
      average_unit_price_90p = average_unit_price * 0.9f;
      average_unit_price_110p = average_unit_price * 1.1f;
    } catch (JSONException e) {
      e.printStackTrace();
    }
    Log.d("CAC", "cases count:" + cases.size());
    mClusterManager.addItems(cases);
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (Case _case : cases) {
      builder.include(_case.getPosition());
    }
    LatLngBounds bounds = builder.build();
    mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 480, 800, 50));
  }
예제 #2
0
 private void loadOfflineHosts() {
   mClusterManager.clearItems();
   mClusterManager.getMarkerCollection().clear();
   mHosts.clear();
   mClusterManager.addItems(starredHosts);
   mClusterManager.cluster();
 }