Xamarin.Forms.Maps - How to fire pin click event programmatically - Pin.SendMarkerClick Method

Joe W 1 Reputation point
2021-04-26T15:17:24.13+00:00

I have a list of map locations when I click one of them I want to zoom to the point on the map and fire a tap event so the pin located there opens its info window. I can zoom to the location on the map without an issue but I can not get the pin to click programmatically. I found the Pin.SendMarkerClick() Method but it appears to not do anything and not be implemented. Does anyone know how I can fire a pin click event without using a custom render? I don't want to have to deal with all the extra overhead of making a custom render for iOS and Android.

using System.ComponentModel;
/// <summary>To be added.</summary>
/// <returns>To be added.</returns>
/// <remarks>To be added.</remarks>
[EditorBrowsable (EditorBrowsableState.Never)]
public bool SendMarkerClick ();

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,364 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,711 Reputation points Microsoft Vendor
    2021-04-27T08:18:33.457+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    You can use Map_PinClicked to handle the PinClick event, If you set e.Handled = true, then Pin selection doesn't work automatically. All pin selection operations are delegated to you.

    In the Page:

     map.PinClicked += Map_PinClicked;  
    
    // Selected Pin changed  
    map.SelectedPinChanged += SelectedPin_Changed;  
    
    map.InfoWindowClicked += InfoWindow_Clicked;  
    
    map.InfoWindowLongClicked += InfoWindow_LongClicked;  
    

    And then clickEvent:

    void Map_PinClicked(object sender, PinClickedEventArgs e)  
        {  
            e.Handled = true;  
      
            uri = new Uri("http://maps.google.com/maps?daddr=" + position.Latitude + "," + position.Longitude);  
            Device.OpenUri(uri);  
      
        }  
    

    You can have a look at here for more information.

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.