Search code examples
google-mapsxamarinbing-mapsxamarin.formsapple-maps

Xamarin.Forms Map Pins


How can i implement click event for Map Pins in Xamarin.Forms ?

I tried Something like this :

var pin = new Pin
    {
        Position = _testPosition,
        Label = string.Format("Latitude: {0},Longitude: {1}", _curentPosition.Latitude, _curentPosition.Longitude)
    } ;

pin.Clicked += (sender, args) =>
        {
            DisplayAlert("Tapped!", "Pin was tapped.", "OK");
        };

But it doesn't worked !

Anyone have idea with this !

Thanks in Advance.


Solution

  • Does the code compile but doesn't fire the event or is it not seeing the clicked property at all?

    Please check which version of Xamarin.Forms you are using.

    The "Clicked" event was added to the xamarin.forms map control in version 1.3.0, but has only actually been working since version 1.4.2-pre2

    The usage is exactly the same as you listed in your example.

    Check that your packages and environment are up to date.

    Some users are reporting issues with the clicked event not firing. If this happens to you, use appropriate Xamarin support channels to report/vote on the issue to get fixed.

    If you can't get it to work and can't wait for Xamarin to fix the issue, you can write custom renderers for the map control and access the native API to handle the tap event. For more information on this, search for "Xamarin.Forms Custom Renderer"