protected void Page_Load(object sender, EventArgs e)
{
string markers = BindMarker();
Literal1.Text = @"
<script type='text/javascript'>
window.onload = function () {
LoadMap();
}
function LoadMap() {
var mapOptions = {
center: new google.maps.LatLng(20.5937,78.9629),
zoom: 4,
};
var myMap = new google.maps.Map(document.getElementById('dvMap'), mapOptions);" + markers + @"
var infowindow = new google.maps.InfoWindow({content: contentString});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(myMap, marker);
});
}
</script>";
}
public string BindMarker()
{
con.Open();
string markers = "";
SqlCommand cmd = new SqlCommand("SELECT Univ_Name, Latitude, Longitude, Univ_Website FROM Location", con);
SqlDataReader reader = cmd.ExecuteReader();
int i = 0;
while (reader.Read())
{
i++;
markers += @"var marker, contentString" + i.ToString() + @" = new google.maps.Marker({position: new google.maps.LatLng(" + reader["Latitude"].ToString() + ", " +
reader["Longitude"].ToString() + ")," + @"map: myMap, title:'" + reader["Univ_Name"].ToString() + "'}, {contentString: new google.maps.InfoWindow('" + reader["Univ_Website"].ToString() + "')});\n";
//Response.Write(markers);
}
return markers;
}}
我的应用程序中有谷歌地图。除了一个问题,一切都正常。我检查了代码,InfoWindow仍未显示。当我在chrome中检查地图时,它显示&#34; Uncaught ReferenceError:未定义contentString&#34;控制台出错。
我似乎无法找到我错误的地方。请帮助解决问题