This project has moved. For the latest updates, please go here.

How to add more than 1 point?

Aug 6, 2015 at 2:51 PM
H! I'm learning to code and I cant to add more than 1 point to my kml file. I'm doing this:
var document = new Document();
document.Id = "Document";
document.Name = "Document";
foreach(AddressessClass item in res)
{
var latlon= locationService.GetLatLongFromAddress(item.address);
var latitude = latlon.Latitude;
var longitude = latlon.Longitude;

coordinates.Add(new SharpKml.Base.Vector(latitude, longitude));
placemark.Name = item.Id;
}
linestring.Coordinates = coordinates;
placemark.Geometry = linestring;
document.AddFeature(placemark);
linestring.Tessellate = true;
linestring.AltitudeMode = AltitudeMode.RelativeToGround;
var kml = new Kml();
kml.Feature = placemark;
KmlFile kmlFile = KmlFile.Create(kml, true);
using (var stream = System.IO.File.OpenWrite(System.IO.Path.GetDirectoryName(conn) + "\\map.kml"))
{
 kmlFile.Save(stream);
 }
My code dont work because but only one point.
Please What can I do for add all foreach point?
Thank you very much!
Coordinator
Aug 7, 2015 at 5:44 AM
If you are trying to add multiple placemarks to the document (which I assume, as inside the foreach you're changing the placemark.Name to the item.Id) then you need to move the call to document.AddFeature inside the loop as well (being careful to not re-use variables like coordinates/linestrng/placemake between iterations (i.e. new them up inside the foreach loop).

If, however, you want to have multiple points in your placemark (a possibility as you're using a LineString) then it should work - what error are you seeing and is there a chance of getting a minimal piece of code showing the problem (the code you posted is not complete).

Sam