How to add custompin in custommap dynamically in a foreach?

i'm creating an app that has to show custom pins based on a condition currently i'm adding two pins each with its own attributes and is working fine, but that was for testing purposes, what i need to do now is adding multiple pins dynamically in a for each.

I'll put first the code that adds 2 static pins (which works) and then my attempt to add the pins dinamically (which is not working, it's not displaying any pins in the map) please can you help me identify what i'm doing wrong in the second attempt.

<br /> public MapPage ()<br /> {<br /> InitializeComponent ();</p> <pre><code> var parkingdata=getparkingdata(); var dataResult = JArray.Parse(parkingdata); var pin = new CustomPin { Pin = new Pin { Type = PinType.Place, Position = new Position(-38.74035548, -72.59119112), Label = "a1", Address = dataResult[0]["addressA"].ToString(), }, Id = "A1", Url = "", state=true }; var pin2 = new CustomPin { Pin = new Pin { Type = PinType.Place, Position = new Position(-38.73949065, -72.58932732), Label = "b2", Address = dataResult[1]["addressA"].ToString(), }, Id = "b2", Url = "", state=false }; customMap.CustomPins = new List<CustomPin> { pin,pin2 }; customMap.Pins.Add (pin.Pin); customMap.Pins.Add (pin2.Pin); }


And this is my failed attempt to add the pins dynamically


public MapPage ()<br /> {</p> <pre><code> InitializeComponent (); var parkingdata=getparkingdata(); var dataResult = JArray.Parse(parkingdata); customMap.CustomPins = new List<CustomPin>(); int counter = 0; string state = ""; Boolean stateB; foreach (var element in dataResult) { if ((int)dataResult[counter]["state"]==0) { stateB = true; state = "busy"; } else { stateB = false; state = "free"; } var pin = new CustomPin { Pin = new Pin { Type = PinType.Place, Position = new Position((double), dataResult[counter]["coordinates_lat"], (double)datosResultadoOcupacion[counter]["coordinates_lon"]), Label = "a1", Address = dataResult[counter]["address"].ToString(), }, Id = state, Url = "", state = stateB }; customMap.Pins.Add(pin.Pin); counter++; } }

Sign In or Register to comment.