我有一個asp.net應用程序,我試圖在其上使用Google地圖。當我嘗試通過字符串數組的JavaScript,每這篇文章:將字符串[]傳遞給javascript
Passing value to javascript from asp.net
我在ASPX形式設置:
var locations = "<%=data %>";
調試正在評估這樣的位置:
var locations = "System.String[]"
;
我的數據屬性設置是這樣的:
protected string[] data;
protected void Page_Load(object sender, EventArgs e)
{
data = new string[] { "26.2486591339111,-80.2002334594727", "26.2344417572021,-80.1393356323242", "26.0818271636963,-80.2083358764648", "26.2701854705811,-80.1152496337891", "26.2009468078613,-80.1440734863281" };
}
我不是在位置得到任何經/緯度值。我究竟做錯了什麼?
我是比較新的Javascript,所以請種:D
謝謝!
編輯#1
我也嘗試「和」的<%=data %>
周圍,既沒有了作用。
編輯#2
的ASPX的情況下,身體可以幫助:
<body>
<div id="map" style="width: 500px; height: 400px;"></div>
<script type="text/javascript">
//var locations = [
// ['Bondi Beach', -33.890542, 151.274856, 4],
// ['Coogee Beach', -33.923036, 151.259052, 5],
// ['Cronulla Beach', -34.028249, 151.157507, 3],
// ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
// ['Maroubra Beach', -33.950198, 151.259302, 1]
//];
var locations = '<%=data %>';
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
var pinColor = "#";
for (k = 0; k < 3; k++) {
pinColor += ("0" + (Math.random() * 256 | 0).toString(16)).substr(-2);
}
var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + pinColor,
new google.maps.Size(21, 34),
new google.maps.Point(0, 0),
new google.maps.Point(10, 34));
var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
new google.maps.Size(40, 37),
new google.maps.Point(0, 0),
new google.maps.Point(12, 35));
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
icon: pinImage,
shadow: pinShadow,
map: map
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
</body>
OP閱讀他的** **其良好的建議 – zgood