After reading some articles on JavaScript objects, I still can't seem to grasp it completely. I managed to convert a JSON string into a JavaScript object following the structure below.
public class LinePoint {
public string Latitude { get; set; }
public string Longitude { get; set; }
public int Pointnumber { get; set; }
}
public class PolyLine {
public List<LinePoint> LinePoints { get; set; }
public int PolyLineNumBer { get; set; }
}
public class RootObject {
public List<PolyLine> PolyLines { get; set; }
}
To plot the Latitude and Longitude properties as polylines on a Google map control, I added the code snippet below to initialize the map. However, I am struggling with looping through the object.
Here is my current code:
var line = JSON.parse(document.getElementById('hdfPolyLines').value);
var path = [];
$.each( /* Looping through list items in RootObject */ ) {
// Parsing the array of LatLngs into Gmap points
for(/* Looping through each latlong in the list of list items */) {
path.push(new google.maps.LatLng( /* Accessing Latitude and Longitude properties from list item */ ));
}
var polyline = new google.maps.Polyline({
path: path,
strokeColor: '#ff0000',
strokeOpacity: 1.0,
strokeWeight: 3
});
polyline.setMap(map);
});
I'm looking for assistance on how to properly loop through the JavaScript object and extract property values. Can someone provide guidance on this?