在Visual Studio项目
问题描述:
连接服务器和客户端,我们在HTML在Visual Studio项目
<!DOCTYPE html>
<html>
<head>
<title>Google Maps</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="js/markers.js">
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
</head>
<body><div id="map"></div>
<input type="button" id="showmarkers" value="Show Markers" />
</body>
</html>
写了这个代码并且该代码在JavaScript
$(document).ready(function() {
$("#map").css({
height:600,
width: 2000
});
var myLatLng = new google.maps.LatLng(31.2402893696987, 34.7672211844361);
MYMAP.init('#map', myLatLng, 11);
$("#showmarkers").click(function(e){
MYMAP.placeMarkers('markers.xml');
});
});
var MYMAP = {
map: null,
bounds: null
}
MYMAP.init = function(selector, latLng, zoom) {
var myOptions = {
zoom:zoom,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map($(selector)[0], myOptions);
this.bounds = new google.maps.LatLngBounds();
}
MYMAP.placeMarkers = function(filename) {
$.get(filename, function(xml){
$(xml).find("marker").each(function(){
var name = $(this).find('name').text();
var address = $(this).find('address').text();
// create a new LatLng point for the marker
var lat = $(this).find('lat').text();
var lng = $(this).find('lng').text();
var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
// extend the bounds to include the new point
MYMAP.bounds.extend(point);
var marker = new google.maps.Marker({
position: point,
map: MYMAP.map
});
var infoWindow = new google.maps.InfoWindow();
var html='<strong>'+name+'</strong.><br />'+address;
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(MYMAP.map, marker);
});
MYMAP.map.fitBounds(MYMAP.bounds);
});
});
}
我们想利用这个代码在我们的ASP上显示谷歌地图。 NET(C#)网站。是否可以将整个代码按原样加载到我们网站上的某个页面上? 谢谢!!!!!
答
是的。将一个新的.aspx
文件添加到您的ASP.NET项目中,并简单地用您的HTML替换其默认内容。
然后,在<head>
部分添加脚本块:
<script language="javascript">
</script>
而在其间,粘贴你的JavaScript代码。
现在从项目中的任何其他页面添加一个指向此页面的链接。
这应该工作得很好。