Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8991533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:44:59+00:00 2026-06-15T22:44:59+00:00

I am trying to loop through xmlnodecollection and get some values for google maps

  • 0

I am trying to loop through xmlnodecollection and get some values for google maps markers. I am trying with dictionary, but its not really working for multiple nodes in the collection.

I want to be able to save more then one key-value pair for the same key. Here is what I have:

        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);

Then in the GenerateMap I want to use those values and put the marker on the map object:

  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);
        }

How can I achieve that? I am using this code in Windows Forms App.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:45:01+00:00Added an answer on June 15, 2026 at 10:45 pm

    You should create a class than contains the properties you need, then create a list of that instead of doing what you’re currently doing. It’s simple and it’ll be easier to read.

    public class MapValues
    {
        public string Latitude { get; set; }
        public string Longitude{ get; set; }
        public string City{ get; set; }
        public string Address{ get; set; }
        public string ZipCode{ get; set; }
        public string State{ get; set; }
    
        public MapValues(string latitude, string longitude, string city, string address, string zipCode, string state)
        {
            this.Latitude = latitude;
            this.Longitude= longitude;
            this.City= city;
            this.Address= address;
            this.ZipCode= zipCode;
            this.State= state;
        }
    }
    

    Change your code to the following:

        List<MapValues> mapValues = new List<MapValues>();
        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(
                new MapValues(
                   row["Latitude"],
                   row["Longitude"],
                   row["City"],
                   row["Address"],
                   row["ZipCode"],
                   row["State"]));
    
            tblResults.Rows.Add(row);
        }
        GenerateMap(mapValues);
    

    Your updated method:

        private void GenerateMap(List<MapValues> 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 (MapValues info in mapInfo)
            {
                PointLatLng pnl = new PointLatLng(Convert.ToDouble(info.Latitude), Convert.ToDouble(info.Longitude));
                GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(pnl);
                MarkerTooltipMode mode = MarkerTooltipMode.OnMouseOver;
                marker.ToolTipMode = mode;
                marker.ToolTipText = info.City + ", " + info.Address + ", " + info.ZipCode + ", " + info.State;
                address_overlay.Markers.Add(marker);
            }
            gMapControl1.Overlays.Add(address_overlay);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to loop through the results from the Last.fm API but it's not
m trying to loop through 3 resultsets and compare their values. bt its throwing
I am trying to loop through this external JSON file(locally stored), but I cannot
Im trying to loop through a json files' object array to access its variables'
I'm trying to loop through Atom feed entries, and get the title attribute lets
I'm trying to loop through my totals in order to get a grand total
I am trying to loop through a query string and pull out certain values
I'm trying to loop through some static properties in a simple static class in
I am trying to loop through some elements in a form (radios, text boxes,
So I am trying to loop through some elements and change some text based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.