0

我们用 HTML 编写了这段代码

<!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#) 网站。是否可以将整个代码按原样加载到我们网站上的某个页面?谢谢!!!!!

4

1 回答 1

0

是的。将一个新.aspx文件添加到您的 ASP.NET 项目中,只需将其默认内容替换为您的 HTML。
然后,在该部分中添加一个脚本块<head>

<script language="javascript">

</script>

并在其中粘贴您的 javascript 代码。

现在从项目中的任何其他页面添加指向此页面的链接。
那应该工作得很好。

于 2012-05-06T07:42:40.260 回答