Save all Marker-Position

Topics: Etc...
Mar 1, 2012 at 1:45 PM

Hello @all,


i can add some markers an then generate a Polygon.

Now i want to save the polygonPoints as txt with Xml.Serialization. I can save 2 points start and end like this that works:

            string filename = saveFileDialog1.FileName;
            TextWriter tx = new StreamWriter(filename);
            XmlSerializer sw = new XmlSerializer(typeof(PointLatLng));
            sw.Serialize(tx, start);
            sw.Serialize(tx, end);


But how i can do it with the polygonPoints? i think i need a counter?

thanks at alll :)


Mar 1, 2012 at 1:57 PM

sw.Serialize(tx, p1);
sw.Serialize(tx, p2);
sw.Serialize(tx, p3);
sw.Serialize(tx, p4);
sw.Serialize(tx, p5);
sw.Serialize(tx, p6);
sw.Serialize(tx, pN);


Mar 6, 2012 at 10:32 AM


i think that is a difficult path, what happend, if i have millions of polygonPoints?

Mar 6, 2012 at 10:39 AM

what if sun explode?

Mar 6, 2012 at 10:40 AM

@hakan80 - put all to some kind of list - List<type> myList, then use method Add - and some part of my code:

  public static void setDataToXML<T>(T data, string fileName)

                XmlSerializer serializer = new XmlSerializer(typeof(T));
                TextWriter textWriter = new StreamWriter(@fileName);
                serializer.Serialize(textWriter, data);
            catch (UnauthorizedAccessException)
                    MessageBoxResult result = MessageBox.Show("Aplication can not write profile file. Check if there is\n enough space on disk.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

Mar 13, 2012 at 11:06 AM

thxxx it was very easy :)

Mar 21, 2012 at 9:42 AM
Edited Mar 21, 2012 at 9:45 AM

hello, me again :)

points save is done, now i want to load this xml-file.

Loading my test.txt file with XmlTextReader, but how can i set the potins as new PointLatLng(lat, lng)?

my code:

XmlTextReader xtr = new XmlTextReader("test.txt");

            while (xtr.Read())
                if (xtr.NodeType == XmlNodeType.Element)
                        if (xtr.Name == "Lat")
                            textBox3.Text += xtr.Value;
                            textBox3.Text += "\r\n";

                        if (xtr.Name == "Lng")
                            textBox4.Text += xtr.Value;

--> now i can see the points Lat and Lng  on each textbox.

Mar 21, 2012 at 12:40 PM

In the same way as writen to file. It will return specified by you structure of data.

  public static T getDataFromXML<T>(string fileName)
            T temp = default(T);

            XmlSerializer serializer = new XmlSerializer(typeof(T));

                TextReader textReader = new StreamReader(@fileName);

                temp = (T)serializer.Deserialize(textReader);


            catch (FileNotFoundException)

                MessageBoxResult result = MessageBox.Show("Description file " + fileName + " doesn't exist", "Error", MessageBoxButton.OK, MessageBoxImage.Error);


            catch (DirectoryNotFoundException e)

                MessageBoxResult result = MessageBox.Show("Directory not found." + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);


            return temp;

Mar 22, 2012 at 10:31 AM
Edited Mar 22, 2012 at 11:43 AM

thxx for help :)

with  this code i can add a polygon from my xml-file,

GMapPolygon P = new GMapPolygon(temp, "test");

but i want to add also my marker for each points  how can i change my List in each point?

i think with index of list: temp[1].Lat.ToString();??

Mar 22, 2012 at 1:14 PM

problem ist solved, with index was the right answer :)

thxx again to radioman and herbatnic

Mar 22, 2012 at 1:36 PM

..i was lazy on this, cheers! ;}