Skip to content Skip to sidebar Skip to footer

Android Google Maps API V2 - Custom Marker .png File Not Recognized By AS

I am trying to customize my marker with a .png file. It is copied under drawable as gsw.png. The code (in MapActivity.java) shows the thumbnail of the icon when I place it in the

Solution 1:

You've written the code correct. If you are using android studio, create 4 folders with names as given below under your project's "YourProjectName\app\src\main\res" folder (Better do it manually on your Project's path, not inside the console):

"drawable-ldpi"

"drawable-mdpi"

"drawable-hdpi"

"drawable-xhdpi"

"drawable-xxhdpi"

Now copy paste your customized marker icon (.png only) to each of those folders(its better if you make different sizes for each folders depending upon the resolution). Save and run your project, It'd definitely work.

If you like to customize your markers more, you can go through these links link1 , link 2


Solution 2:

Android won't load PNGs this way -- don't ask me why. One option is to save the PNG as a BMP, but maybe you don't want to do this because you're concerned about cross-compatibility with another application. Whatever your reason, I found this code to be very useful:

Bitmap img = BitmapFactory.decodeResource(getResources(),R.drawable.your_drawable);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(img);
marker.icon(bitmapDescriptor);

Solution 3:

I tried to rename using the refactor option, but it did not work. However, encouraged by ztan's suggestion, I opened the PNG file in Paint and saved it as a bitmap. Then, I deleted the PNG in drawable using the refactor option, and copied the new BMP. It now works fine.


Post a Comment for "Android Google Maps API V2 - Custom Marker .png File Not Recognized By AS"