Reputation: 401
I have a geocoder and I try with that one create pins on my map, but with my code I only manage to get 1 pin on the map.. my code:
Geocoder gc = new Geocoder ();
var possibleAddresses = await gc.GetPositionsForAddressAsync ("Adress1");
foreach (var address in possibleAddresses) {
var pin = new Pin ();
pin.Position = new Position (address.Latitude, address.Longitude);
pin.Label = "test1";
pin.Address = "test1";
theMap.Pins.Add (pin);
}
var possibleAddresses2 = await gc.GetPositionsForAddressAsync ("Adress2");
foreach (var address2 in possibleAddresses) {
var pin = new Pin();
pin.Position = new Position (address2.Latitude, address2.Longitude);
pin.Label = "test2";
pin.Address = "test2";
pin.Clicked += onButtonClicked1;
theMap.Pins.Add(pin);
}
it only shows my first adress and not the second one when I type in 2 different adresses.
Upvotes: 0
Views: 40
Reputation: 89102
You are iterating over the results from the first GeoCoder call in both loops, so the same pin is being added twice
foreach (var address2 in possibleAddresses) {
should be
foreach (var address2 in possibleAddresses2) {
Upvotes: 2