C# ClientScript.RegisterStartupScript+;谷歌地图
我在使用地理编码和clientscript.registerstartupscript使我的google地图正常工作时遇到问题。我知道我的GoogleJavaScript很好(在其他页面上使用),但它甚至没有达到要求。我有这个功能的工作在其他地方的网站,无法找出为什么它不会工作!非常令人沮丧!!请参见下面的我的代码: .aspx:C# ClientScript.RegisterStartupScript+;谷歌地图,c#,javascript,html,C#,Javascript,Html,我在使用地理编码和clientscript.registerstartupscript使我的google地图正常工作时遇到问题。我知道我的GoogleJavaScript很好(在其他页面上使用),但它甚至没有达到要求。我有这个功能的工作在其他地方的网站,无法找出为什么它不会工作!非常令人沮丧!!请参见下面的我的代码: .aspx: <script> var geocoder; var map; function initialize() { geocoder = n
<script>
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
codeAddress();
}
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode({ 'address': address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<body onload="initialize()">
地图必须初始化,因为它显示的是空的GoogleMapShell,但没有填充
Firebug在页面底部显示:
代码地址();
我使用下面的代码实现了这一点。
注意:变量message&locationList的值来自codebehind,请使用公共变量并在html中分配它
<html>
<head id="Head1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var infowindow;
var geocoder;
var message = "<font style='font-family:Arial;font-size:12px;color:blue;'>206B Signal Hill Drive, <br/>Statesville, NC 28625 USA</font>"; //<%= Message%>
var locationList = "35.793286,-80.855383"; //<%= LocationList%>
var args = locationList.split(",");
function initialize() {
geocoder = new google.maps.Geocoder();
var myLatlng = new google.maps.LatLng(args[0], args[1]);
var myOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var location = new google.maps.LatLng(args[0], args[1])
var marker = new google.maps.Marker({
position: location,
map: map
});
marker.setTitle(message.replace(/(<([^>]+)>)/ig, ""));
attachSecretMessage(marker, 0);
}
function attachSecretMessage(marker, number) {
infowindow = new google.maps.InfoWindow(
{ content: message,
size: new google.maps.Size(50, 50)
});
infowindow.open(map, marker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
</script>
</head>
<body onload="initialize();">
<form method="post" id="Form1">
<div id="map_canvas" style="width: 763px; height: 340px;padding-top:100px;">
</div>
</form>
</body>
</html>
var映射;
var信息窗口;
var地理编码器;
var message=“206B美国北卡罗来纳州斯塔茨维尔市信号山公路,邮编:28625”//
var locationList=“35.793286,-80.855383”//
var args=locationList.split(“,”);
函数初始化(){
geocoder=新的google.maps.geocoder();
var mylatng=new google.maps.LatLng(args[0],args[1]);
变量myOptions={
缩放:15,
中心:myLatlng,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
var location=new google.maps.LatLng(args[0],args[1])
var marker=new google.maps.marker({
位置:位置,,
地图:地图
});
marker.setTitle(message.replace(/(]+)>)/ig,“”);
attachSecretMessage(标记,0);
}
函数attachSecretMessage(标记、编号){
infowindow=新建google.maps.infowindow(
{内容:信息,
大小:新谷歌地图大小(50,50)
});
信息窗口。打开(地图、标记);
google.maps.event.addListener(标记'click',函数(){
信息窗口。打开(地图、标记);
});
}
<html>
<head id="Head1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var infowindow;
var geocoder;
var message = "<font style='font-family:Arial;font-size:12px;color:blue;'>206B Signal Hill Drive, <br/>Statesville, NC 28625 USA</font>"; //<%= Message%>
var locationList = "35.793286,-80.855383"; //<%= LocationList%>
var args = locationList.split(",");
function initialize() {
geocoder = new google.maps.Geocoder();
var myLatlng = new google.maps.LatLng(args[0], args[1]);
var myOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var location = new google.maps.LatLng(args[0], args[1])
var marker = new google.maps.Marker({
position: location,
map: map
});
marker.setTitle(message.replace(/(<([^>]+)>)/ig, ""));
attachSecretMessage(marker, 0);
}
function attachSecretMessage(marker, number) {
infowindow = new google.maps.InfoWindow(
{ content: message,
size: new google.maps.Size(50, 50)
});
infowindow.open(map, marker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
</script>
</head>
<body onload="initialize();">
<form method="post" id="Form1">
<div id="map_canvas" style="width: 763px; height: 340px;padding-top:100px;">
</div>
</form>
</body>
</html>