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 Forms App에서이 코드를 사용하고 있습니다. 미리 감사드립니다.
사용'system.linq.xml'와'ToLookup'
는 다음에 코드를 변경– Jodrell