开发者

Scale Map Markers by Zoom, Android

开发者 https://www.devze.com 2023-01-12 00:20 出处:网络
I havelot 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.

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 imag开发者_如何转开发e depending on the zoom factor?


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);


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


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));
0

精彩评论

暂无评论...
验证码 换一张
取 消