gpt4 book ai didi

javascript - 我在 asp.net 中使用 google map multi markers

转载 作者:行者123 更新时间:2023-11-28 04:18:58 25 4
gpt4 key购买 nike

我在 asp.net 中使用 google map multi markers,这里我需要将数组值从服务器端发送到客户端变量。我正在使用“ClientScript.RegisterArrayDeclaration”将数组传递给我的客户端变量。但它不起作用。请帮助我。我需要在页面加载时传递值。 “位置”是我的java脚本变量 *

<html>
<head>

<title>Google Maps Multiple Markers</title>
<script src="http://maps.google.com/maps/api/js?key=My KEy" type="text/javascript"></script>
</head>
<body>
<center>
<div id="map" style="height: 500px; width: 700px;">
</div>
</center>
<script type="text/javascript">
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: new google.maps.LatLng(9.918648010, 78.12000),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
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>
</html>

*

  protected void Page_Load(object sender, EventArgs e)
{
List<String> oGeocodeList = new List<String>
{
" ['Bala', 9.91864810526, 78.1203081843780, 4] ",
" ['ganesh', 9.91864, 78.12, 5] ",
" ['santhosh', 9.9186, 78.120, 3] ",
" ['test', 9.9186481, 78.12030, 2] ",
" ['test2', 9.918670, 78.12840, 1] "
};
var geocodevalues = string.Join(",", oGeocodeList.ToArray());
ClientScript.RegisterArrayDeclaration("locations", geocodevalues);

}

最佳答案

在您的示例中, map 在 locations 变量在页面上定义之前初始化。一种选择是在页面加载后初始化 map :

function initMap() {

var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: new google.maps.LatLng(9.918648010, 78.12000),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
for (var i = 0; i < locations.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}

}
google.maps.event.addDomListener(window, 'load', initMap);

关于javascript - 我在 asp.net 中使用 google map multi markers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42316528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com