Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How create a custom InfoWindow in GoogleMaps

KymusKymus Member ✭✭

I need to create a custom InfoWindow in GoogleMaps, which can show my information.

My XAML code:
mapc:CustomMap MapType="Street" x:Name="my">
</mapc:CustomMap

A CustomMap.cs code

public class CustomMap:Map { }

A CustomMapRenderer.cs code

public class CustomMapRenderer : MapRenderer
{

    private Activity m_context;

    public GoogleMap customMap;

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

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

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

        if (e.NewElement != null)
        {
            CustomMap formsMap = (CustomMap)e.NewElement;
            MapView nativeMap = Control as MapView;

            m_View = nativeMap;

            nativeMap = (MapView)m_context.LayoutInflater.Inflate(Resource.Layout.XamarinMapInfoWindow, null);

        }
    }}

What I need add for working of this code?

Best Answers

Answers

  • KymusKymus Member ✭✭

    Yes, but it`s code for Xamarin.Forms.Maps and I use Xamarin.Forms.GoogleMaps. How I can do this?

  • ColeXColeX Member, Xamarin Team Xamurai
    edited August 13

    Yes, i'm talking about Xamarin.Forms.GoogleMaps, make your custom renderer class inherit from GoogleMap.IInfoWindowAdapter interface and implement GetInfoContents method .

  • KymusKymus Member ✭✭

    I added to CustomMapRenderer.cs this functions:

    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 = marker;
                if (customPin == null)
                {
                    throw new Exception("Custom pin not found");
                }
    
    
                    view = inflater.Inflate(Resource.Layout.XamarinMapInfoWindow, null);
    
                return view;
            }
            return null;
        }
    
        public Android.Views.View GetInfoWindow(Marker marker)
        {
            return null;
        }
    

    But it doesnt work. the program still calls the standard InfoWindow but not CustomInfoWindow.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited August 14

    Can you use Debugger to check if GetInfoContents is triggered or not ?

  • KymusKymus Member ✭✭

    GetInfoContents isn`t triggered

  • KymusKymus Member ✭✭

    Yes, my class extends GoogleMap.IInfoWindowAdapter interface

  • KymusKymus Member ✭✭
    edited August 14

    Map in this sample doesn`t work. I see compass and white screen

Sign In or Register to comment.