Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

GoogleMap Marker icon issue in renderer

$
0
0

I'm making renderers in my project, so that the PinType enum will actually have an effect by changing the color of the pins. But whenever I use a non-default icon for the native Marker, it draws as the default icon on top of my icon, with the default disappearing on click.

Here are some screenshots from using marker.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen)):

image image

And here are some from using marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_launcher)) (my app icon):

image image

And here is my renderer code:

[assembly: ExportRenderer(typeof(ExtendedMap), typeof(ExtendedMapRenderer))]
namespace eLationTechnician.Forms.Droid.Renderers
{
    public class ExtendedMapRenderer : MapRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);

            if(e.NewElement != null)
            {
                UpdatePins();
            }
        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if(e.PropertyName == "Pins")
            {
                UpdatePins();
            }
        }

        private void UpdatePins()
        {
            NativeMap.Clear();

            foreach(var pin in Map.Pins)
            {
                var marker = new MarkerOptions()
                    .SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude))
                    .SetTitle(pin.Label).SetSnippet(pin.Address);

                float hue = 0.0f;
                switch (pin.Type)
                {
                    case PinType.Generic:
                    case PinType.SearchResult:
                    {
                        hue = BitmapDescriptorFactory.HueRed;
                        break;
                    }
                    case PinType.SavedPin:
                    {
                        hue = BitmapDescriptorFactory.HueGreen;
                        break;
                    }
                    case PinType.Place:
                    {
                        hue = BitmapDescriptorFactory.HueBlue;
                        break;
                    }
                }

                marker.SetIcon(BitmapDescriptorFactory.DefaultMarker(hue));

                NativeMap.AddMarker(marker);
            }
        }
    }
}

Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>