[Solved] How to set second label on InfoWindow xamarin map


You could get the CustomPin with the GetCustomPin method in the custom renderer like the sample in your above link.

 CustomPin GetCustomPin(Marker annotation)
    {
        var position = new Position(annotation.Position.Latitude, annotation.Position.Longitude);
        foreach (var pin in customPins)
        {
            if (pin.Position == position)
            {
                return pin;
            }
        }
        return null;
    }

and in your public Android.Views.View GetInfoContents(Marker marker) method:

public Android.Views.View GetInfoContents(Marker marker)
{
    var inflater = Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService) as Android.Views.LayoutInflater;
    if (inflater != null)
    {
        Android.Views.View view;

        var customPin = GetCustomPin(marker);
        if (customPin == null)
        {
            throw new Exception("Custom pin not found");
        }

        if (customPin.Name.Equals("Xamarin"))
        {
            view = inflater.Inflate(Resource.Layout.XamarinMapInfoWindow, null);
        }
        else
        {
            view = inflater.Inflate(Resource.Layout.MapInfoWindow, null);
        }

        CustomPin pin = GetCustomPin(marker);
        int CodeNum  = pin.CodeNum;          //get the pin,then get the codenum and alertlevel
        string AlertLevel  = pin.AlertLevel;

        var infoTitle = view.FindViewById<TextView>(Resource.Id.InfoWindowTitle);
        var infoSubtitle = view.FindViewById<TextView>(Resource.Id.InfoWindowSubtitle);
        var infoSubtitle2 = view.FindViewById<TextView>(Resource.Id.InfoWindowSubtitle2);
        var infoSubtitle3 = view.FindViewById<TextView>(Resource.Id.InfoWindowSubtitle3);// create the third TextView in your xml

        if (infoTitle != null)
        {
            infoTitle.Text = marker.Title;
        }
        if (infoSubtitle != null)
        {
            infoSubtitle.Text = marker.Snippet;
        }
        if (infoSubtitle2 != null)
        {
            infoSubtitle2.Text = CodeNum  +"";
        }
        
        if (infoSubtitle3 != null)
        {
            infoSubtitle3.Text = AlertLevel;
        }

        return view;
    }
    return null;
}

Update :

public partial class YouPage: ContentPage
{
    public YouPage()
    {
        InitializeComponent();
    }

    protected async override void OnAppearing()
    {
        base.OnAppearing();
        ...  //you get the data from MySql,if you have several data,you need a loop
        var codeNum = xxx;
        var level = xxx;
        CustomPin pin = new CustomPin();
        pin.CodeNum = codeNum;
        pin.AlertLevel = level ;
        yourcustomMap.Pins.Add(pin);
    }
      

6

solved How to set second label on InfoWindow xamarin map