调用Pin Map控件Xamarin forms pcl上的click事件

本文关键字:pcl 上的 click 事件 forms Xamarin Pin Map 控件 调用 | 更新日期: 2023-09-27 18:18:16

我在网上找,但找不到任何东西,我正在使用地图控制Xamarin表单pcl。我必须说,当我点击地图上的Pin(谷歌地图)时,我找到了要触发的事件。谁能给我点建议?谢谢你。

var map = new Map(
                    MapSpan.FromCenterAndRadius(
                        new Position(lat, lon), Distance.FromMiles(50)))
                    {
                        IsShowingUser = true,
                        HeightRequest = CrossScreen.Current.Size.Height,
                        WidthRequest = CrossScreen.Current.Size.Width,
                        VerticalOptions = LayoutOptions.FillAndExpand
                    };
                    RGL_Locations = RGL_Locations.OrderByDescending(x => x.RGL_DateTime).ToList();
                    foreach (RGL_Locations item in RGL_Locations)
                    {
                        map.Pins.Add(new Pin { Type = PinType.Generic, Label = item.RGL_MCC_Numero_Serie_MS.ToString(), Position = new Position(item.RGL_Latitudine, item.RGL_Longitudine) });
                    }
                    map.Pins.Add(new Pin { Type = PinType.Generic, Label = "Io sono qui!", Position = new Position(lat, lon)});
                    var stack = new StackLayout { Spacing = 0 };
                    stack.Children.Add(map);
                    Content = stack;

解决方案:

foreach (RGL_Locations item in RGL_Locations)
                    {
                        var pin = new Pin
                        {   
                            Type = PinType.Place,
                            Position = new Position(item.RGL_Latitudine, item.RGL_Longitudine),
                            Label = "Clicca qui per aprire",
                            Address = "Numero di serie macchina: " + item.RGL_MCC_Numero_Serie_MS.ToString()
                        };
                        pin.Clicked += Pin_Clicked;
                        map.Pins.Add(pin);                        
                    }

调用Pin Map控件Xamarin forms pcl上的click事件

Xamarin.Forms.Map Pin类有一个Clicked事件:

var position = new Position(32, -13); 
var pin = new Pin
{
    Type = PinType.Place,
    Position = position,
    Label = "custom pin",
    Address = "custom detail info"
};
pin.Clicked +=  (object sender, EventArgs e) =>
{
    var p = sender as Pin;
};

裁判:Xamarin.Forms.Maps.Pin.Clicked