Show / Hide Bookmarks as zoom Zoom on Android map

3

I'm developing an android app that will contain many markers on the map, and to not get too messy I would like that if you were zooming in on the markups going into Hide, I tried the following code:

@Override
public void onCameraChange(CameraPosition cameraPosition) {
    if (cameraPosition.zoom > 7) {
        Toast.makeText(this,"teste",Toast.LENGTH_LONG).show();
        marker.setVisible(true);
    }else{
        marker.setVisible(false);
   }
}

When the zoom is greater than 7 it would be for it to show, but it does not work.

    
asked by anonymous 01.08.2016 / 20:22

2 answers

3

Google Maps Android API Utility Library provides, among other things, classes for Manage bookmark groups . By grouping the bookmarks, you can place a large number of bookmarks on a map without making the map difficult to read.

Using api is easy, there are 5 steps to implement:

1 - Implement a ClusterItem to represent each of the markers on the map.

public class Marcador implements ClusterItem {
    private final LatLng mPosition;

    public Marcador(double lat, double lng) {
        mPosition = new LatLng(lat, lng);
    }

    @Override
    public LatLng getPosition() {
        return mPosition;
    }
}

2 - Use a ClusterManager to group and manage bookmarks ( ClusterItem ).

private ClusterManager<MyItem> mClusterManager;
mClusterManager = new ClusterManager<Marcador>(this, getMap());

3 - Assign the ClusterManager to OnCameraChangeListener() of the map.

getMap().setOnCameraChangeListener(mClusterManager);

4 - If you want to add specific functionality in response to a click on the marker, assign the ClusterManager to OnMarkerClickListener() of the map.

getMap().setOnMarkerClickListener(mClusterManager);

5 - Add each of the ClusterItem tags to ClusterManager

double lat = 51.5145160;
double lng = -0.1270060;
Marcador marcador = new Marcador(lat, lng);
mClusterManager.addItem(marcador);  

//Adicionar outros marcadores
......
......

Done, ClusterManager will manage your bookmarks, making sure the map is always easy to read.

To have Api available add the following dependency to the Gradle build file of the application:

dependencies {
    compile 'com.google.maps.android:android-maps-utils:0.4+'
}

Font: Google Maps Android Marker Clustering Utility

    
01.08.2016 / 23:06
1

There is a method that is functional, not indicated but right to disappear with all markers at the same time according to the zoom value.

Implement the class with:

public class MapsActivity extends SupportMapFragment implements OnMapReadyCallback GoogleMap.OnCameraChangeListener {

Creating your map:

@Override
public void onMapReady(GoogleMap googleMap) {
    mapa = googleMap;
    mapa.setOnCameraChangeListener(getOnCameraChangeListener());
}

Implements and methods:

public GoogleMap.OnCameraChangeListener getOnCameraChangeListener()
{
    return  new GoogleMap.OnCameraChangeListener()
    {
    @Override
    public void onCameraChange(CameraPosition position) {

        if(position.zoom >7)
            marker.setVisible(true);
        else
            marker.setVisible(false);

    }};
}

@Override
public void onCameraChange(CameraPosition cameraPosition) {

}
    
02.08.2016 / 04:24