コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_map);

    FragmentManager fm = getSupportFragmentManager();
    SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map);
    GoogleMap map = f.getExtendedMap();

    map.addMarker(new MarkerOptions().position(new LatLng(0, 0)));
    map.addMarker(new MarkerOptions().position(new LatLng(15, 3)));
    map.addMarker(new MarkerOptions().position(new LatLng(15, 3)));

    ClusterOptionsProvider provider =
        new ClusterOptionsProvider() {

          @Override
          public ClusterOptions getClusterOptions(List<Marker> markers) {
            return new ClusterOptions()
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
          }
        };
    map.setClustering(new ClusteringSettings().clusterOptionsProvider(provider));

    map.setOnMarkerClickListener(
        new GoogleMap.OnMarkerClickListener() {

          @Override
          public boolean onMarkerClick(Marker marker) {
            Toast.makeText(
                    SimpleMapActivity.this,
                    "Clicked marker at: " + marker.getPosition(),
                    Toast.LENGTH_SHORT)
                .show();
            return false;
          }
        });
  }
コード例 #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.
  */
 private void setUpMap() {
   mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
 }