0

What is the proper object to inherit from when trying to add a Tap handler on a map on android? I've tried with MapView, MapRenderer, MapActivity, Overlay to name a few.

CustomMapRenderer.cs

Totally wrong, but showing what I've been trying.

using Xamarin.Forms;
using nuMaps;
using nuMaps.Droid;
using Android.Gms.Maps;
using System;
using Xamarin.Forms.Maps.Android;
using Xamarin.Forms.Platform.Android;
using Android.App;
using Xamarin.Forms.Maps;
using Android.Widget;
using Android.GoogleMaps;
namespace nuMaps.Droid
{
    public class CustomMapRenderer  MapActivity
    {
        public override bool OnTouchEvent (Android.Views.MotionEvent e, Android.GoogleMaps.MapView mapView)
        {
            Console.WriteLine (e.Action);
            return base.OnTouchEvent (e, mapView);
        }
    }
}

MapPage.xaml

<?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:local="clr-namespace:nuMaps;assembly=nuMaps"
    x:Class="nuMaps.MapPage">
    <ContentPage.Content>
        <AbsoluteLayout>
            <local:CustomMap
                x:Name="MyMap"
                IsShowingUser="true"
                MapType="Hybrid"
                AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
                AbsoluteLayout.LayoutFlags="All"
            />
        </AbsoluteLayout>
    </ContentPage.Content>
</ContentPage>
Don Boots
  • 2,028
  • 2
  • 18
  • 26

1 Answers1

1

I implemented simple extended map control to test custom map renderer. You can have a look here. Not sure if this is that you need. The only purpose of this class is to provide tap location for all three platforms. It's pure sample code, not for production, works fine for me but if you have any problems please tell me.

Artur Shamsutdinov
  • 3,127
  • 3
  • 21
  • 39
  • This seems to work perfectly and is quite thorough! Thank you so much! The only part that I don't get the call to handler(this,e) in ExtendedMap/ExtendedMap.cs/OnTap(TapEventArgs e). Is this some sort of reserved logic that needs to happen? – Don Boots Apr 15 '15 at 14:20
  • Actually I figured it out after going through it more extensively. Looks like render is just an instance of the inline class TapEventArgs. Thanks again! – Don Boots Apr 15 '15 at 18:08
  • handler is just for safe event invocation http://stackoverflow.com/questions/3668953/raise-event-thread-safely-best-practice – Artur Shamsutdinov Apr 15 '15 at 21:04