我做了这段代码
但只有第一点出现,其他人没有。点之间的路径也是隐藏的,我不知道为什么。
@model IList @ {Layout =“〜/ Views / Shared / _Lay2.cshtml”;} var culture = System.Globalization.CultureInfo.GetCultureInfo(“en-US”);}
@for (int marker=2;marker<@Model.Count; marker++)
{
<script type="text/javascript">
alert(@marker);
var myOptions = {zoom: 30, center: myLatLng, mapTypeId: google.maps.MapTypeId.TERRAIN };
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var flightPlanCoordinates = [
new google.maps.LatLng(@Model[marker].ToString(culture), @Model[marker + 1].ToString(culture)),];
var flightmarker = new google.maps.Marker({
position: new google.maps.LatLng(@Model[marker].ToString(culture), @Model[marker + 1].ToString(culture)),
map: map,
title: " denden" });var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
</script>
marker++;
}
任何建议?
答案 0 :(得分:0)
看起来你是在循环的每次迭代中重新创建地图。也许尝试这样的事情:
@model IList<float>
@{ Layout = "~/Views/Shared/_Lay2.cshtml";
var culture = System.Globalization.CultureInfo.GetCultureInfo("en-US");}
<body onload="initialize(@Model[0].ToString(culture), @Model[1].ToString(culture))">
<table style="width: 100%; height: 70%"> <tr>
<td style="width: 100%"><div id="map_canvas" style="width: 100%; height: 500px;"></div></td>
<script type="text/javascript">
var myOptions = {zoom: 30,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN };
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
@for (int marker=2;marker<@Model.Count; marker += 2) {
var flightPlanCoordinates = [
new google.maps.LatLng(@Model[marker].ToString(culture), @Model[marker + 1].ToString(culture)),];
var flightmarker = new google.maps.Marker({
position: new google.maps.LatLng(@Model[marker].ToString(culture), @Model[marker + 1].ToString(culture)),
map: map,
title: " denden" });var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
</script>
</tr>
</table>
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>