1

온라인 상태이지만 아무 것도 찾을 수 없습니다. Map control Xamarin forms pcl을 사용하고 있습니다. 그리고지도에서 핀 (Google지도)을 클릭하면 트리거 할 이벤트를 찾습니다. 누구든지 내게 조언 할 수 있습니까? 고맙습니다.핀 맵 컨트롤에서 click 이벤트를 호출합니다. Xamarin forms pcl

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

Xamarin.Forms.MapPin 클래스는 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

+0

당신은 또한 핀의 목록에 바인딩 할 수 있습니다? 귀하의 예제는 단일 객체를 참조합니다. 목록의 모든 핀에 이벤트를 연결하려면 어떻게해야합니까? –

+0

@ Mr.Developer 당신은 각각의 핀에 같은 이벤트 델리게이트를 할당해야합니다 ... 당신은 항상 반복을 통해 과제를 수행하는 List Extension을 쓸 수 있습니다 .... – SushiHangover

+0

나는 부분적인 도움으로 해결했습니다, 감사합니다 –

관련 문제