我已经编写了这段代码来在asp.net网页上用javascript代码显示地图和标记:
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script>
var myCenter;
var center;
var isButtonClick = false;
function initialize(x, y) {
var mapProp = {
center: new google.maps.LatLng(x, y),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
myCenter: center;
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(x, y),
animation: google.maps.Animation.BOUNCE
});
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', function () { if (!isButtonClick) initialize(0, 0) });
</script>
并在asp按钮单击事件中编写此代码以将值发送到java脚本函数:
Page.ClientScript.RegisterStartupScript(this.GetType(), "beh", "isButtonClick=true;initialize(35.878987,46.279637);", true);
每件事都有效!但我想向javascript函数发送两个或更多位置或值,例如发送此值:45.123321,35.123345
35.123321,45.123321
45.123456,34.123454
并标记地图上的所有点。我怎么能这样做?注意:上传值必须用asp按钮事件发送到功能,我有下行代码:
String[,] myArr = new String[4, 1];
myArr[0, 0] = "45.123321";
myArr[1, 0] = "35.454345";
myArr[2, 0] = "20.123321";
我怎样才能将数组发送到功能?
答案 0 :(得分:1)
function initialize(markersData) {
var mapProp = {
center: new google.maps.LatLng(x, y),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
myCenter: center;
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
for(var i=0;i<markersData.length;i++){
var marker = new google.maps.Marker({
position: new google.maps.LatLng(markersData[i,0], markersData[i,1]),
animation: google.maps.Animation.BOUNCE
});
marker.setMap(map);
}
}
initialize(markersData);
在C#decalre你像这样的数组
// ... Create 2D array of strings.
float[,] markersData= new flaot[,]
{
{45.123321,35.123345},
{35.123321,45.123321},
{45.123456,41.123454}
};
Page.ClientScript.RegisterStartupScript(this.GetType(), "beh", "isButtonClick=true;initialize(markersData);", true);