2012-04-29 2 views
4

나는 작동하는 Google지도 스크립트가 있지만 내 asp.net 콘텐츠 페이지에 추가하는 방법을 알아낼 수 없습니다. 스크립트를 페이지에 추가하는 적절한 방법은 무엇입니까?asp.net 콘텐츠 페이지에 스크립트 추가

참조 코드 :

<%@ Page Title="Our Location" Language="VB"  MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="Location.aspx.vb" Inherits="About_Location" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 

<script type="text/javascript" 
    src="http://maps.google.com/maps/api/js?sensor=false"> 
</script> 

<style type="text/css"> 
html { height: 100% } 
body { height: 100%; margin: 0px; padding: 0px } 
##map{ height: 100% } 
</style> 

</asp:Content> 


<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server" OnLoad="codeAddress()"> 

<script type= "text/javascript"> 

var geocoder; 
var map; 
var marker; 

function codeAddress() { 
    alert("hello") 


    //initializes the map 

    //create geocoder 
    geocoder = new google.maps.Geocoder(); 
    //set options for the map being created 
    var myOptions = { 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    //create map instance and pass it the myOptions object literal 
    map = new google.maps.Map(document.getElementById("map"), myOptions); 

    //geocode to get the lat and lng points of the given address 
    geocoder.geocode({ 'address': 'New York, New York'}, function (results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      //if geocoder finds location 
      //center the map on the latlng points of the given address 
      map.setCenter(results[0].geometry.location); 
      map.setOptions({ zoom: 18 }); 
      //create marker and place it on the address 
      marker = new google.maps.Marker({ 
       map: map, 
       position: results[0].geometry.location, 
       title: 'New York, New York' 
      }); 
     } 
     else { 
      //if geocoder cannot find location, alert user 
      alert("Could not find location"); 
     } 
    }); 




} 





</script> 

<div id="map" style="width:700px; height:400px;"></div> 

</asp:Content> 

답변

4

는, 별도의 js 파일에 스크립트를 넣어 당신이 구글처럼 선언은 스크립트를 매핑합니다. 그런 다음 호출해야합니다. 아마도이 "#map"div id를 스크립트의 매개 변수로 보내야합니다. 자바 스크립트에서는 하드 코드하지 않아야합니다. 이 경우

당신은 스크립트 관리자와 페이지로드하고 싶지 : BTW

ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowGoogleMap", "codeAddress('map');", true); 

. Google지도 서버 컨트롤을 사용할 수있는 Google지도의 경우 서버 측 관리지도를 사용하는 것이 훨씬 쉽습니다.

http://googlemap.codeplex.com/

관련 문제