0

We all know that some of the predefined landmarks on Google Maps does not appear on a lower zoom level, but on a higher zoom level, it suddenly appears. I would like to know If I can make a customized marker not appear at lower zoom levels, then appear at higher ones.

EDIT: Here is a snippet of my code.

 // Changing marker icon
   marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.gasbig));


   // adding marker
  map.addMarker(marker);

  //position on Center

  CameraPosition cameraPosition = new CameraPosition.Builder().target(
          new LatLng(14.635356, 121.03272914)).zoom(16).build();

  map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

  map.setOnCameraChangeListener(new OnCameraChangeListener() {

        @Override
        public void onCameraChange(CameraPosition arg0) {
            if(arg0.zoom > 7){
                marker.visible(true);

            }


        }
    });

I tried the suggestion of MaciejGórski but the marker still appears on all zoom levels. I'm sorry about the question I'm still an android newbie.

Thanks in advance.

Jeongbebs
  • 4,100
  • 7
  • 34
  • 60

2 Answers2

3

You can do that for any Marker you want: call setVisible in OnCameraChangeListener.onCameraChange callback with true or false depending on CameraPosition.zoom value.

Edit after question edit:

You need to keep a reference to Marker instead of MarkerOptions:

// adding marker
marker = map.addMarker(markerOptions);

and call setVisible on that marker:

    @Override
    public void onCameraChange(CameraPosition cameraPosition) {
        marker.setVisible(cameraPosition.zoom > 7);
    }

Note: setVisible is always called there, but this might not be optimal when using many Markers.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
0

You could possibly do it by modifying my answer to: Android Maps v2 - animate camera to include most markers

Otherwise using Android Maps Extensions might be a good choice. No experince with your specific needs though.

Just realized I might have misunderstood the question. Thought you meant your own markers. Nevertheless have a look at the extensions library. Could very well be that they have something useful.

Community
  • 1
  • 1
cYrixmorten
  • 7,110
  • 3
  • 25
  • 33
  • Extensions lib cannot do that (yet), but might be a good alternative when instead of hiding markers on lower zoom levels, you want them to be grouped and easily accessible on any zoom level. – MaciejGórski Oct 02 '13 at 16:26
  • Just seemed as if it can from: http://stackoverflow.com/questions/18450081/add-markers-dynamically-on-google-maps-v2-for-android – cYrixmorten Oct 02 '13 at 16:33
  • 1
    Miguel, as I understand it, wants something like [MarkerManager in the javascript API](https://developers.google.com/maps/articles/toomanymarkers#markermanager). – MaciejGórski Oct 02 '13 at 18:57
  • Hi @MaciejGórski do you have some tutorial or a code that involves MarkerManager for android? I can't find one. – Jeongbebs Oct 03 '13 at 02:23
  • @MiguelRivera I don't know if such tutorial exists. – MaciejGórski Oct 03 '13 at 06:05