8

I have lot of markers on my map. Zooming in each marker shows me a position. but zooming out the markers are overlapping each other and it is more difficult do determine the position of a marker.

Is there a way to scale the marker image depending on the zoom factor?

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601

3 Answers3

6

Depends on how you draw your marker. If your marker is just a bitmap/drawable, simply use matrix.postScale()

Matrix matrix = new Matrix();
matrix.postScale(2f, 2f); // douple the size
canvas.drawBitmap(mBitmap, matrix, mPaint);
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
  • Can you provide a more detailed method of how to do this? – ferguior Sep 13 '11 at 20:10
  • @ferguior: What exactly do you need? Drawing a scaled image is now answered in me edited post... – WarrenFaith Sep 13 '11 at 20:43
  • 2
    My doubt is more about how to handle the scaling, when to do it and how to measure it so that I can apply the right scale. Also, this code you posted, in which class would it go? In the Maps View, or in the OverlayItem, or in the ItemizedItem? – ferguior Sep 13 '11 at 20:51
  • @ferguior: The calculation for the scaling might be tricky and I think you just need to play with it to find a good scaling factor. The code I posted should be implemented where you draw your marker/overlay. Short check revealed that you can use the `draw()` method in `ItemizedOverlay` – WarrenFaith Sep 13 '11 at 22:10
3

Markers do not change size based on zoom. Use GroundOverlays if you desire this effect. src

 GoogleMap map = ...; // get a map.
 BitmapDescriptor image = ...; // get an image.
 LatLngBounds bounds = ...; // get a bounds
 // Adds a ground overlay with 50% transparency.
 GroundOverlay groundOverlay = map.addGroundOverlay(new GroundOverlayOptions()
     .image(image)
     .positionFromBounds(bounds)
     .transparency(0.5));

A ground overlay is an image that is fixed to a map and scales with the map zoom. Please see the API for more info

Josh
  • 268
  • 2
  • 14
  • But then you have to calculate the bounds of the Ground Overlay rather than supplying a position. This makes it a less than ideal solution. – Andrew S Jun 18 '14 at 20:06
1

A simple form is.

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.raw.ic_car_1);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); 
        googleMap.addGroundOverlay(new GroundOverlayOptions()
             .image(bitmapDescriptor)
             .position(latLng,100));
Ronald Coarite
  • 4,460
  • 27
  • 31