0
我試圖循環訪問xmlnodecollection並獲取一些Google地圖標記的值。 我正在嘗試使用字典,但它並不真正適用於集合中的多個節點。 我希望能夠爲同一個鍵保存更多的一個鍵,值對,並且如果有人有一些想法我可以做什麼,那麼更歡迎來幫助我。 以下是我有:c#爲同一個鍵值數組多個值
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窗體應用程序中使用此代碼。 在此先感謝,Laziale
使用'system.linq.xml'和'ToLookup' – Jodrell