/**
   * 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));
  }
Exemplo n.º 2
0
  private void setUpMap() {

    // Rotate gestures probably aren't needed here and can be disorienting for some of our users.
    mMap.getUiSettings().setRotateGesturesEnabled(false);

    mMap.setOnCameraChangeListener(this);

    CameraPosition position = null;

    // If we were launched with an intent asking us to zoom to a member
    Intent receivedIntent = getIntent();
    if (receivedIntent.hasExtra("target_map_latlng")) {
      LatLng targetLatLng = receivedIntent.getParcelableExtra("target_map_latlng");
      position =
          new CameraPosition(
              targetLatLng, getResources().getInteger(R.integer.map_showhost_zoom), 0, 0);
    }

    if (position == null) {
      position = getSavedCameraPosition();
    }
    if (position != null) {
      mMap.moveCamera(CameraUpdateFactory.newCameraPosition(position));
      // The move itself will end up setting the mlastCameraPosition.
    }

    mClusterManager = new ClusterManager<HostBriefInfo>(this, mMap);
    mClusterManager.setAlgorithm(
        new PreCachingAlgorithmDecorator<HostBriefInfo>(
            new WSNonHierarchicalDistanceBasedAlgorithm<HostBriefInfo>(this)));
    mMap.setOnMarkerClickListener(mClusterManager);
    mMap.setOnInfoWindowClickListener(mClusterManager);
    mClusterManager.setOnClusterClickListener(this);
    mClusterManager.setOnClusterInfoWindowClickListener(this);
    mClusterManager.setOnClusterItemClickListener(this);
    mClusterManager.setOnClusterItemInfoWindowClickListener(this);
    mClusterManager.setRenderer(new HostRenderer());
    mMap.setInfoWindowAdapter(mClusterManager.getMarkerManager());
    mClusterManager
        .getClusterMarkerCollection()
        .setOnInfoWindowAdapter(new ClusterInfoWindowAdapter(getLayoutInflater()));
    mClusterManager
        .getMarkerCollection()
        .setOnInfoWindowAdapter(new SingleHostInfoWindowAdapter(getLayoutInflater()));
  }
Exemplo n.º 3
0
  /**
   * This is where we can add markers or lines, add listeners or move the camera. In this case, we
   * just add a marker near Africa.
   *
   * <p>This should only be called once and when we are sure that {@link #mMap} is not null.
   *
   * @param latitude
   * @param longitude
   */
  private void setUpMap(double latitude, double longitude) {
    LatLng latLng = new LatLng(latitude, longitude);
    Log.e("latLng", "lat:" + String.valueOf(latitude) + " lng:" + String.valueOf(longitude));
    mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14));

    clusterManager = new ClusterManager<MarkerData>(this, mMap);
    clusterManager.setRenderer(new MarkerRender());

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

    clusterManager.setOnClusterClickListener(this);
    clusterManager.setOnClusterInfoWindowClickListener(this);
    clusterManager.setOnClusterItemClickListener(this);
    clusterManager.setOnClusterItemInfoWindowClickListener(this);

    addItems();
    clusterManager.cluster();
  }