Google Maps API: Swap default marker image

Asked

Viewed 1,030 times

1

Hello, I’m testing the Google Maps API on my android app, and I learned that there is a way to change the icon of the default marker, however, when I added my PNG image to the project, the icon got an absurdly large size. How can I not do this, as long as my image has a resolution of 512x512?

1 answer

2


You need to have this image in various dimensions, so the android itself will take charge of climbing the best quality depending on the device. Below the necessary sizes of icons:

MDPI - 48px

HDPI - 72px

XHDPI - 96px

XXHDPI - 144px

XXXHDPI - 192px

Then set the location of the image in the icon.

private static final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
  private Marker melbourne = mMap.addMarker(new MarkerOptions()
                            .position(MELBOURNE)
                            .title("Melbourne")
                            .snippet("Population: 4,137,400")
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
  • Thank you so much! Now comes that relief from those who have suffered so much so far hahaha

  • haha that good! Now go :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.