[英]How do i add multiple markers in xamarin using for each loop with a list model
I am trying to add pins on my Xamarin android application.我正在尝试在我的 Xamarin android 应用程序上添加引脚。 I have already set up the map and I need to create pins from a list array that contains the latitudes and longitudes.
我已经设置了 map,我需要从包含纬度和经度的列表数组中创建引脚。 I know it's quite simple but I'm stuck here.
我知道这很简单,但我被困在这里。
Below is my sample code.下面是我的示例代码。
public class Farmers
{
public int farmers_id { get; set; }
public string Farmer_name { get; set; }
public double Long { get; set; }
public double Lat { get; set; }
}
private void AddMarker()
{
List<Farmers> farmers =GetFarmers();
foreach (Farmers p in farmers)
{
//HOW TO ADD NEW PINS FOR EACH FARMER ON THE MAP WITH FARMER NAME AS LABEL
}
}
I'm using Xamarin.Forms.Maps
.我正在使用
Xamarin.Forms.Maps
。 The issue is more of how to loop.问题更多在于如何循环。
create a pin and add it to the map创建一个引脚并将其添加到 map
foreach (Farmers p in farmers)
{
var pin = new Pin();
pin.Label = p.Farmer_name;
pin.Type = PinType.Place;
pin.Position = new Position(p.Lat,p.Long);
myMap.Pins.Add(pin);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.