我正在尝试将谷歌地图添加到我的网站,但我希望能够从数据库加载值,而不是修复该位置的纬度和经度。如何从 vb.net 获取变量并将其传递给 javascript?我试过:
<% Response.Write("<script>
function initialize() {
var myLatlng = new google.maps.LatLng(1.123456, 1.123456);
var mapOptions = {
zoom: 16,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'KH Automotive Location'
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>")%>
和
new google.maps.LatLng(<%=latitude%>, <%=longitude%>);
请帮忙。谢谢
最佳答案
有时,当我需要绝对确定(例如使用翻译/本地化的字符串)内容时,我会将其写到页面上某处的隐藏 DIV(或隐藏的 INPUT)中。
<div style='display:none' id='my_data'>stuffstuffstuff</div>
然后我只读取 DIV(或 INPUT,无论我使用什么)的内容。在其中添加“runat=server”,并能够从代码隐藏中写入它。
关于javascript - 如何将 vb.net 变量加载到 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26248215/