简体   繁体   English

如何在 xamarin 中添加多个标记,使用列表 model 的每个循环

[英]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.

相关问题 如何以编程方式在Google地图中添加多个标记? - How do I add multiple markers in Google Maps programmatically? 如何在列表中循环播放类的每一列 <class> 在C#中使用每个 - How do i loop each column of a class in List<class> using for each in c# 如何制作清单清单? 然后添加到每个List值? - How do I make List of Lists? And then add to each List values? 如何在使用 Jetbrain Rider 时在 Xamarin 中添加图像? - How do I add an Image in Xamarin while using Jetbrain Rider? 如何一次或循环添加列表中的多个元素? - How do you add multiple elements in a list at once or with a loop? 如何使用一种模型和一种视图添加多个表? - How do I add multiple tables using one model and one view? (XAMARIN ANDROID)-如何遍历列表中的每个循环 <T> 并抓住每个项目,然后传递到数组适配器,再传递到列表视图 - (XAMARIN ANDROID) - How can I for each loop through a List<T> and grab each item then pass to a array adapter then to a listview 我如何使用多条目循环将用户输入的字符串值存储在列表中 c# - how do i store a string value from user input in a list using loop for multiple entry c# 如何在foreach循环中添加到并行列表 - how do I add to a parallel list in a foreach loop 如何在 Xamarin 中添加计时器? - How do I add a timer in Xamarin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM