2016-03-29 4 views
0

2つのピンをグループに分ける必要があります。なぜなら、それらをフィルタリングするとき、どのピンがどのカテゴリに属する​​のかを知る必要があるからです。データから受け取っているピンを別のカテゴリに分けるにはどうしたらいいですか?

これは私がそれらを受け取る方法です。したがって、int app.value1が0で、もう1つがapp.value2が0の場合はロードするグループが1つあります。

私はそれらを分離する必要がある理由は、私が分離する必要があるためです二つ。多分2つの異なるリストをしなければならないでしょうか?それとも良い方法がありますか?

List<Pin> myPins = new List<Pin>(); 

private async Task<List<Pin>> LoadData() 
{ 
    var pins = new List<Pin>(); 

    var getItems = await phpApi.getInfo(); 

     foreach (var currentItem in getItems["results"]) { 

      longString = currentItem ["long"].ToString(); 
      latString = currentItem ["lat"].ToString(); 

       if (App.value1 == 0) { //so this below is the first group of pins then 
         var pin = new Pin(); 
         pin.Position = new Position (latString, longString); 
         pin.Label = "testlabel"; 
         pin.Address = "testadress"; 

         pins.Add (pin); 
        } 

       if (App.value2 == 0) { //second group of pins 
       //i add pins here as well (so the same code as App.value1), but this intvalue is connected to a different "button" 
         pins.Add (pin); 
       } 

     } 
    } 

とピンdoesntのは、インクルードが属するグループを知っているので、これは今働いていない私のフィルタである:

private async void FilterPins (string filter) 
    { 
     map.Pins.Clear(); 

     foreach(Pin p in myPins) { 

      if (string.IsNullOrWhiteSpace(filter) || (p.Label.Contains(filter)))  { 
       map.Pins.Add (p); //this is just a searchfilter via my searchbar that isnt working when I add the code below. If i remove the code below this function works. 
      } 

      if (App.value1 == 0) { 
       map.Pins.Add (p); 
       System.Diagnostics.Debug.WriteLine ("add"); 
      } 


      if (App.value2 == 0) { 
       map.Pins.Add (p); 
       System.Diagnostics.Debug.WriteLine ("add"); 
      } 

     } 
    } 

答えて

0

Pinクラスはsealedhttps://developer.xamarin.com/api/type/Xamarin.Forms.Maps.Pin/)であるので、それは少し難しいです回避する。ただし、それぞれのPinオブジェクトをフィルタに基づいて配置できる2つの別々のList<Pin>を作成することができます。するとPinオブジェクトの一覧表示されているMap.Pinsオブジェクトをスワップすることができます。

https://developer.xamarin.com/api/property/Xamarin.Forms.Maps.Map.Pins/

そうでなければ、Pinオブジェクトとその中のstring Categoryを含む別のPOCOオブジェクトを作成することができます。

EX:

public class PinWithCategory { public Pin Pin {get; set;} public string Category {get; set;} }

+0

うん、私はこのの助けを借りてそれを解決するために管理しました。すごい、thx – Yannick

関連する問題