我有一个带有 GPS 坐标列表的文本文件。我正在尝试在文档中的每个坐标上放置一个标记。问题是文档的长度和我拥有它的方式发生了变化,每次迭代都会替换标记。如何为每个纬度/经度点添加标记?
以下是相关代码:
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();
}