在Pin Map控件上调用click事件Xamarin表单pcl

时间:2016-11-16 14:06:32

标签: c# google-maps xamarin xamarin.forms portable-class-library

我正在网上查找但找不到任何东西,我正在使用地图控件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);                        
                    }

1 个答案:

答案 0 :(得分:4)

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