我想从VIEWBAG中传递值作为我在C#中的模型中的LatLons数组。我不知道如何动态循环的Viewbag阵列和这些cordinates添加到我的JavaScript数组传递到:用Google Maps和C#创建一个动态多段线.net
// Create an instance of Google map
var map = new GMap2(document.getElementById("map"));
// Tell the map where to start
map.setCenter(new GLatLng(59.3324, 17.8857), 9);
// Create an array with points
var points = [
new GLatLng(59.6919, 17.8582),
new GLatLng(59.3030, 18.0395),
new GLatLng(58.9789, 17.5341)
];
// Create a new polyline
var polyline = new GPolyline(points, '#ff0000', 5, 0.7);
// Add the polyline to the map using map.addOverlay()
map.addOverlay(polyline);
我想要做的事就像上面,但没有静态数组。
在此先感谢!
编辑:
目前我有:
var points = [];
@foreach (var item in ViewBag.LatLons)
{
<text>
points.push(new GLatLng(@item.Latitude, @item.Longitude);
</text>
}
但是,谷歌地图将不会显示在此加入,然而,点正确地从viewbag数据迭代通过。
这行: points.push(新的GLatLng(@ item.Latitude,@ item.Longitude); 应该是: points.push(新的GLatLng( @ item.Latitude,@ item.Longitude)); –