Can GMapControl load a kml file?

Topics: Feature Requests
Mar 7, 2012 at 1:52 PM

Hi,everyone. I really want to make sure if I can add my own data to a GMapControl.

In this case,I need a GMapControl loading google map,and I also  need cover my own kml data to the map.but till now I'm not sure if the GMapControl can load a kml file.If can,how to make it?


Mar 7, 2012 at 4:30 PM

kml isn't supported

Mar 13, 2012 at 9:59 AM

There are libraries on the web for reading kml files, (or you can write your own - it's a published standard) and it's easy enough then to make and display markers for the data.

Apr 4, 2012 at 3:15 PM


Apr 5, 2012 at 3:14 PM
Edited Apr 5, 2012 at 3:18 PM

KML file is XML. A simple example of a draft. Copy kml from url  and use gpoints to construct Polygon 


            var doc = XDocument.Load(@"C:\Users\MyHome\Desktop\test.kml");            
            var elements = doc.Root.Elements().Elements().Elements();
            var xlineStyle = elements.Where(x=>x.Name.LocalName.ToUpper().Equals("LineStyle".ToUpper()));
            var xpolyStyle = elements.Where(x => x.Name.LocalName.ToUpper().Equals("PolyStyle".ToUpper()));
            var xpolygon = elements.Where(x => x.Name.LocalName.ToUpper().Equals("Polygon".ToUpper())).Elements();
            var points = xpolygon.Where(x => x.Name.LocalName.ToUpper().Equals("outerBoundaryIs".ToUpper())).Elements().Where(x=>x.Name.LocalName.ToUpper().Equals("LinearRing".ToUpper())).FirstOrDefault();
            var s = points.Value.Split('\n').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
            var gpoints = new List<PointLatLng>();
            foreach (var item in s)
                var value = item.Trim().Split(',');
                var lat = double.Parse(value[0], CultureInfo.InvariantCulture);
                var lng = double.Parse(value[1], CultureInfo.InvariantCulture);
                gpoints.Add(new PointLatLng(){Lat = lat,Lng = lng});