amay077 / Xamarin.Forms.GoogleMaps

Map library for Xamarin.Forms using Google maps API
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
MIT License
546 stars 349 forks source link

Problems with custom Pins #584

Closed stesvis closed 6 years ago

stesvis commented 6 years ago

VERSIONS

PLATFORMS

ACTUAL BEHAVIOR

Unhandled Exception:

Java.Lang.IllegalArgumentException: Failed to decode image. The provided image must be a Bitmap.

EXPECTED BEHAVIOR

I would expect to see the map pin using my custom image.

HOW TO REPRODUCE

  1. I placed ic_vgpin.png in the drawable (android) and Resources (iOS) folder.
  2. Tried Build Action = AndroidAsset and AndroidResource
  3. Ran the code snippet below
var pin = new Pin()
                    {
                        Type = PinType.Place,
                        Label = geoLocation.FormattedAddress,
                        Address = geoLocation.FormattedAddress,
                        Position = new Position(geoLocation.Latitude, geoLocation.Longitude),
                        Rotation = 15f,
                        Icon = BitmapDescriptorFactory.FromBundle("ic_vgpin.png"),
                        IsVisible = true
                    };
                    map.Pins.Add(pin);
                    await map.MoveCamera(CameraUpdateFactory.NewPositionZoom(new Position(geoLocation.Latitude, geoLocation.Longitude), 13));

Is it ok to place my pin image in the drawable/Resources folder? Anything else i am missing?

fulopbede commented 6 years ago

I've placed the icon in the "AndroidProject"/Assets folder, and it works fine for me

stesvis commented 6 years ago

Thanks! That was it, and in iOS it goes in the root folder.

marciordonez commented 5 years ago

Remember to set Build Action file property to "AndroidAsset"

image

mr5z commented 4 years ago

Why can't it be put into drawables folder? It would be better if it's there since we can support multiple resolutions.

Also, most of the time, the file extension is unnecessary when referring to embedded images. That's how XF works so I think we copy it?

ybadragon commented 4 years ago

Yeah I'm with @mr5z on this one. It should use the drawables folder instead. I have a custom image in my drawables folder so we can support multiple resolutions.