我正在尝试遍历 xmlnodecollection 并获取谷歌地图标记的一些值。我正在尝试使用字典,但它不适用于集合中的多个节点。
我希望能够为同一个键保存一个以上的键值对。这是我所拥有的:
Dictionary<string, string> mapValues = new Dictionary<string, string>();
foreach (XmlNode node in listProperties)
{
row = tblResults.NewRow();
row["Id"] = node.Attributes[0].Value;
row["Latitude"] = node["Location"].Attributes[0].Value;
row["Longitude"] = node["Location"].Attributes[1].Value;
row["City"] = node["Location"].Attributes[2].Value;
row["Address"] = node["Location"].Attributes[3].Value;
row["ZipCode"] = node["Location"].Attributes[4].Value;
row["State"] = node["Location"].Attributes[5].Value;
mapValues.Add("Latitude", node["Location"].Attributes[0].Value);
mapValues.Add("Longitude", node["Location"].Attributes[1].Value);
mapValues.Add("City", node["Location"].Attributes[2].Value);
mapValues.Add("Address", node["Location"].Attributes[3].Value);
mapValues.Add("ZipCode", node["Location"].Attributes[4].Value);
mapValues.Add("State", node["Location"].Attributes[5].Value);
tblResults.Rows.Add(row);
}
GenerateMap(mapValues);
然后在 GenerateMap 我想使用这些值并将标记放在地图对象上:
private void GenerateMap(Dictionary<string, string> mapInfo)
{
gMapControl1.SetCurrentPositionByKeywords("USA");
gMapControl1.MinZoom = 3;
gMapControl1.MaxZoom = 17;
gMapControl1.Zoom = 4;
gMapControl1.Manager.Mode = GMap.NET.AccessMode.ServerAndCache;
gMapControl1.Position = new GMap.NET.PointLatLng(29.60862, -82.43821);
gMapControl1.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;
GMap.NET.WindowsForms.GMapOverlay address_overlay = new GMap.NET.WindowsForms.GMapOverlay(gMapControl1, "Address1");
foreach (KeyValuePair<string, string> info in mapInfo)
{
PointLatLng pnl = new PointLatLng(Convert.ToDouble(info.Value[0]), Convert.ToDouble(info.Value[1]));
GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(pnl);
MarkerTooltipMode mode = MarkerTooltipMode.OnMouseOver;
marker.ToolTipMode = mode;
marker.ToolTipText = info.Value[2] + ", " + info.Value[3] + ", " + info.Value[4] + ", " + info.Value[5];
address_overlay.Markers.Add(marker);
}
gMapControl1.Overlays.Add(address_overlay);
}
我怎样才能做到这一点?我在 Windows 窗体应用程序中使用此代码。