2017-01-24 7 views
-1

Androidでプログラミングするのは初めてです。私はコードでいくつかのマーカーを表示するアプリケーションを開発しています。クラスタを追加すると、いくつかのデフォルトポイントが表示されます。 クラスタ内のこれらのデフォルトポイントをどのように変更して、必要なポイントにマーカーを追加するにはどうすればいいですか?希望の場所にマーカーが付いたクラスタ

private void addItems() { 

    double lat = 3.424014; 
    double lng = -76.536218; 

    for (int i = 0; i < 5; i++) { 

     double offset = i/60d; 
     lat = lat + offset; 
     lng = lng + offset; 
     MyItem offsetItem = new MyItem(lat, lng); 
     mClusterManager.addItem(offsetItem); 

    } 
} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_maps); 
    // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 
    btnclute=(Button)findViewById(R.id.btn_cluster); 

    //cluster 

    btnclute.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(3.422504, -76.538128), 13)); 
      mClusterManager = new ClusterManager<MyItem>(getBaseContext(), mMap); 

      mMap.setOnCameraIdleListener(mClusterManager); 
      mMap.setOnMarkerClickListener(mClusterManager); 

      addItems(); 

     } 
    }); 


} 

/** 
* 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; 
    mapa= googleMap; 


    // Add a marker in Sydney and move the camera 
    //LatLng sydney = new LatLng(-34, 151); 

    //Marker 

    //Estadio 
    LatLng home = new LatLng(3.429862, -76.541336); 
    dato=getResources().getString(R.string.estadio); 
    mMap.addMarker(new MarkerOptions().position(home).title(dato) 
      .icon(BitmapDescriptorFactory.fromResource(R.drawable.estadio))); 
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home, 13)); 

    //Sebastian Belalcazar 

    LatLng home1 = new LatLng(3.449151, -76.545185); 
    dato1=getResources().getString(R.string.sebas); 
    mMap.addMarker(new MarkerOptions().position(home1).title(dato1) 
      .icon(BitmapDescriptorFactory.fromResource(R.drawable.sebastian))); 
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home1, 13)); 

    //Cristo Rey 

    LatLng home2 = new LatLng(3.435855, -76.564840); 
    dato2=getResources().getString(R.string.rey); 
    mMap.addMarker(new MarkerOptions().position(home2).title(dato2) 
      .icon(BitmapDescriptorFactory.fromResource(R.drawable.cristo))); 
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home2, 13)); 

    //Tres cruces 

    LatLng home3 = new LatLng(3.467800, -76.545473); 
    mMap.addMarker(new MarkerOptions().position(home3).title(getResources().getString(R.string.cruces)) 
      .icon(BitmapDescriptorFactory.fromResource(R.drawable.tres))); 
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home3, 13)); 

    //Plaza de Caicedo 

    LatLng home5 = new LatLng(3.451864, -76.532479); 
    dato3=getResources().getString(R.string.plaza); 
    dato4="-" + getResources().getString(R.string.caicedo); 
    dato5="-" + getResources().getString(R.string.pedro); 
    dato6="-" + getResources().getString(R.string.palacio); 
    mMap.addMarker(new MarkerOptions().position(home5).title(dato3) 
      .snippet(dato4 + "\n" + 
      dato5 + "\n" + 
      dato6) 
      .icon(BitmapDescriptorFactory.fromResource(R.drawable.plaza))); 
    mapa.moveCamera(CameraUpdateFactory.newLatLngZoom(home5, 13)); 

答えて

0

クラスタがグリッド内で整列しないようにアルゴリズムを設定する必要があります。

NonHierarchicalDistanceBasedAlgorithm<ClusterItem> algo = new NonHierarchicalDistanceBasedAlgorithm<>(); 
mClusterManager.setAlgorithm(algo); 

//If that isn't enough you can change the latlng 
Collection<ClusterItem> col = algo.getItems(); 
    for (ClusterItem clusterItem : col) { 
     clusterItem.getPosition().latitude = yourNewLatitude; 
     clusterItem.getPosition().longitude = yourNewLongitude; 
    } 
関連する問題