4

How can I scale marker size in android google maps fragment, when zoom on map changes. Get same effect like uber has with cars. enter image description here

pepela
  • 423
  • 5
  • 17

2 Answers2

3

Here is a method to create marker based on sizes:

public Bitmap resizeMapIcons(String iconName,int width, int height){
    Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(),getResources().getIdentifier(iconName, "drawable", getPackageName()));
    Bitmap resizedBitmap = Bitmap.createScaledBitmap(imageBitmap, width, height, false);
    return resizedBitmap;
}

Then you must add TouchOverly to map by calling :

mapView.getOverlays().add(new TouchOverlay());

Where the TouchOverly is:

private class TouchOverlay extends com.google.android.maps.Overlay {
        int lastZoomLevel = -1;

        @Override
        public boolean onTouchEvent(MotionEvent event, MapView mapview) {
            if (event.getAction() == 1) {
                lastZoomLevel = mapView.getZoomLevel();

                if (mapView.getZoomLevel() != lastZoomLevel) {
                    onZoom(mapView.getZoomLevel());
                    lastZoomLevel = mapView.getZoomLevel();
                }
            }
            return false;
        }
    }

And finally refresh markers on map in onZoom :

private void onZoom(int level){
    // resizeMapIcons
    // clear markers
    // add new markers
}
Dadroid
  • 1,444
  • 15
  • 16
0

if marker is a bitmap image we can change its width and height using

Bitmap.createScaledBitmap(bitmapDp, width, hight, false); we need to call this from onCameraMove() call back.

 for (int k = 0; k < markers.size(); k++) {
                resizedBitmap(bitmapArrayList.get(k), 250, 250);
                markers.get(k).setIcon(BitmapDescriptorFactory.fromBitmap(resizedBitmap));
            }



 public Bitmap resizedBitmap(Bitmap bitmapDp, int width, int hight) {
    resizedBitmap = Bitmap.createScaledBitmap(bitmapDp, width, hight, false);
    return resizedBitmap;

}
androidLearner
  • 1,654
  • 1
  • 7
  • 13