使用Json Array设置polyLine Path

时间:2014-08-09 10:13:12

标签: c# javascript asp.net ajax google-maps

我创建了一个方法,它使用c#从数据库返回纬度和经度数组,现在我想将此列表传递给JavaScript以在谷歌地图上绑定poly_line路径。

1 个答案:

答案 0 :(得分:2)

var polyOptions = {
    strokeColor: '#000000',
    strokeOpacity: 1.0,
    strokeWeight: 3
}
poly = new google.maps.Polyline(polyOptions);
poly.setMap(map);

var path = new MVCArray;

$.getJSON('json.cs', function(data) {
    //var items = [];
    $.each(data, function(key, val) {
            path.push(new google.maps.LatLng(val.lat, val.longi));
    });

    // now update your polyline to use this path
    poly.setPath(path);
});


<body onload="initialize()">
  <div id="map_canvas" style="width:90%; height:100%"></div>

</body>

</html>

For Reference