如何在C#中的Gmap上添加多个制造商 [英] How to add multiple makers on Gmap in c#
问题描述
我有一个带有GPS坐标列表的文本文件.我正在尝试在文档的每个坐标上放置一个标记.问题在于文档的长度和我的更改方式,每次迭代都会替换标记.如何为每个纬度/经度点添加标记?
I have a text file with a list of GPS coordinates. I am trying to place a marker on each of the coordinates from the document. The problem is that the lengths of the documents change and the way I have it, the marker gets replaced with every iteration. How do I add a marker for each lat/lon point?
以下是相关代码:
private GMapOverlay gMapOverlay;
private GMapMarker marker;
gmap.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;
gmap.MinZoom = 2;
gmap.MaxZoom = 25;
gmap.Zoom = 5;
gmap.ShowCenter = false;
gmap.DragButton = MouseButtons.Left;
//setup the map overlay for displaying routes/points
gMapOverlay = new GMapOverlay("Path");
gmap.Overlays.Add(gMapOverlay);
gMapOverlay.Markers.Clear();
gMapOverlay.Routes.Clear();
//GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(0, 0), GMarkerGoogleType.green);
marker = new GMarkerGoogle(new PointLatLng(0, 0), GMarkerGoogleType.green);
marker.IsVisible = false;
marker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
marker.ToolTipText = "Starting Point";
gMapOverlay.Markers.Add(marker);
private void btn_KMLFile_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog4.ShowDialog();
if (result == DialogResult.OK)
{
string filename = openFileDialog4.FileName;
string[] lines = System.IO.File.ReadAllLines(filename);
foreach (string line in lines)
{
string[] Data_Array = line.Split(',');
Double londecimal = Convert.ToDouble(Data_Array[0]);
Double latdecimal = Convert.ToDouble(Data_Array[1]);
marker.Position = new PointLatLng(latdecimal, londecimal);
marker.IsVisible = true;
gmap.Update();
}
}
}
private void openFileDialog4_FileOk(object sender, CancelEventArgs e)
{
OpenFileDialog openFileDialog4 = new OpenFileDialog();
}
推荐答案
标记可以进入Markers
集合:
public readonly ObservableCollection<GMapMarker> Markers;
只需将标记添加到集合中,就像处理单个marker
一样.
Just add the markers to the collection as you do with your single marker
.
编辑
我假设使用WPF客户端,所以如果您使用WinForms,则没有Observable Collection
.您是否尝试过像原始标记一样向集合中添加新标记?因此,在您的循环中:
I was assuming a WPF client, so there's no Observable Collection
if you are using WinForms. Have you tried to add a new marker to the collection as you do with your original marker? So in your loop:
string[] Data_Array = line.Split(',');
Double londecimal = Convert.ToDouble(Data_Array[0]);
Double latdecimal = Convert.ToDouble(Data_Array[1]);
// add a new one here
var marker = new GMarkerGoogle(new PointLatLng(latdecimal, londecimal), GMarkerGoogleType.green);
marker.IsVisible = true;
gMapOverlay.Markers.Add(marker);
这篇关于如何在C#中的Gmap上添加多个制造商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!