コード例 #1
0
ファイル: Maps2Activity.java プロジェクト: gebuh/wsandroid
  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()));
  }
コード例 #2
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();
  }