我已经在JavaScript对象上找到了一些文章但是我似乎还没有弄明白这一点。我将A JSON字符串转换为javascript对象,如下所示。通过JavaScript对象循环绘制多段线谷歌地图
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; }
}
因为我想每个列表项的所有纬度和经度属性来绘制它们作为我添加以下代码到地图的初始化一个谷歌地图控制折线。我只是不知道如何循环对象。
这是我的代码到目前为止。
var line = JSON.parse(document.getElementById('hdfPolyLines').value);
var path = [];
$.each(/* Listitem in rootobject */) {
// Parse the array of LatLngs into Gmap points
for(/* each latlong in the list of listitems */){
path.push(new google.maps.LatLng(// Latitude en Longitude properties from listitems */));
}
var polyline = new google.maps.Polyline({
path: path,
strokeColor: '#ff0000',
strokeOpacity: 1.0,
strokeWeight: 3
});
polyline.setMap(map);
});
有人能告诉我如何通过javascript对象循环并获取属性值吗?
该代码看起来不像javascript,它看起来像java。 – geocodezip
这不是Java,它是C# –