Unable to show custom markers in Google Maps

Hi,

After update to the new version of Xamarin.Forms, custom pins are no longer visible on the map.

This is the custom renderer I use:

<<<
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.Gms.Maps;
using Android.Gms.Maps.Model;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using WaterMeter;
using WaterMeter.Customizations;
using WaterMeter.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Maps;
using Xamarin.Forms.Maps.Android;

[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
namespace WaterMeter.Droid
{
    public class CustomMapRenderer : MapRenderer
    {
        List<CustomPin> customPins;

        public CustomMapRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Map> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                ;
            }

            if (e.NewElement != null)
            {
                var formsMap = (CustomMap)e.NewElement;
                customPins = formsMap.CustomPins;
                Control.GetMapAsync(this);
            }
        }

        protected override MarkerOptions CreateMarker(Pin pin)
        {
            var marker = new MarkerOptions();
            marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
            marker.SetTitle(pin.Label);
            marker.SetSnippet(pin.Address);
            CustomPin customPin = GetCustomPin(pin);
            if (customPin.Value > 0)
            {
                marker.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
                //marker.SetIcon(ImageSource.FromResource("WaterMeter.Assets.Images.WaterMeterIcon.png", assembly);
            }
            else
            {
                marker.SetIcon(BitmapDescriptorFactory.DefaultMarker());
            }
            return marker;
        }

        CustomPin GetCustomPin(Pin pin)
        {
            foreach (var p in customPins)
            {
                if (p.Id == pin.Id)
                {
                    return p;
                }
            }
            return null;
        }

        protected override void OnMapReady(GoogleMap map)
        {
            base.OnMapReady(map);
        }
    }
}
>>>

The custom renderer is triggered, but the custom pins are not visible.

The xaml for the map page is this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
             xmlns:local="clr-namespace:WaterMeter.Customizations;assembly=WaterMeter"
             x:Class="WaterMeter.MapPage">
    <ContentPage.Content>
        <local:CustomMap x:Name="locationsMap" 
              HorizontalOptions="FillAndExpand"
              VerticalOptions="FillAndExpand"
              IsShowingUser="True"
              MapType="Hybrid"/>
    </ContentPage.Content>
</ContentPage>

Xamarin.Forms     version = 2.5.0.122203
Xamarin.Forms.Maps     version = 2.5.0.122203
Xaml.Plugin.Geolocator     version = 4.2.0

Can you hel me?



1 Reply

VM Vijayakumar Mariappan Syncfusion Team May 28, 2018 11:55 AM UTC

Hi Claudio Riccardi, 
 
It look like you are facing issues in Xamarin.Forms maps. You can log your issues under the below links. 
  
 
Regards, 
Vijay 


Loader.
Up arrow icon