2014-07-15 2 views
1

서버 측에서 Bing지도 압핀을 추가하고 싶습니다. 아래 코드를 시도했지만 압핀이 나타나지 않습니다. 아래 코드를 개선하고이 작업을 수행하는 방법에 대한 제안 사항이 있습니까?Bing지도 압핀이 나타나지 않음

protected void Page_Load(object sender, EventArgs e) 
{ 
    GetLocation(sender,e); 
} 

protected void GetLocation(object sender, EventArgs e) 
{ 
    DataTable tblLocation = new DataTable(); 
    string query = "SELECT Latitude, Longitude FROM Location "; 
    if (textbox1.Text != "") 
    { 
     textbox1.Text = Convert.ToString(Convert.ToInt32(textbox1.Text) + 1); 
    } 
    else 
    { 
     textbox1.Text = "1"; 
    } 
    query += " WHERE num = " + textbox1.Text; 
    SqlDataAdapter adapter = new SqlDataAdapter(); 
    string connString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; 
    SqlConnection conn = new SqlConnection(connString); 
    conn.Open(); 
    adapter.SelectCommand = new SqlCommand(query, conn); 
    adapter.Fill(tblLocation); 
    conn.Close(); 

    if (tblLocation.Rows.Count > 0) 
    { 
     longitude.Text = tblLocation.Rows[0]["Longitude"].ToString(); 
     latitude.Text = tblLocation.Rows[0]["Latitude"].ToString(); 
     string script = "UpdatePushPin(+ " + latitude.Text + " , " + longitude.Text + ");"; 
     ScriptManager.RegisterStartupScript(this, this.GetType(), "Key", script, true); 
    } 
    else 
    { 
     textbox1.Text = Convert.ToString(Convert.ToInt32(textbox1.Text) - 1); 
    } 
} 

Asp.net :

<script type='text/javascript' src='http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0'></script> 
<script type='text/javascript'> 
    var map; 
    function GetMap() { 
     map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), 
      {credentials: "mycredentials", 
      center: new Microsoft.Maps.Location(12.2, 103.7), 
      mapTypeId: Microsoft.Maps.MapTypeId.road, 
      zoom: 12 
     }); 
    } 
    function UpdatePushPin(x, y) { 
     map.entities.clear(); 
     var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(x, y)); 
     map.entities.push(pushpin); 
    } 
</script> 

답변

0

I

나는 빙지도 아약스 제어 V7.0

C 번호와 아래의 프로그램 asp.net 및 C#을 사용하고 있습니다 위도와 경도 요소의 ID가 ASP.NET에 정보가 추가되어 다른 것으로 의심됩니다. 생성 된 HTML을 검사하면 ID가 단순히 '위도'또는 '경도'가 아닌 ctl00 $ MainContent $ 경도와 같은 것일 수 있습니다. 이 문제를 해결하려면 ASP.NET 컨트롤의 ClientID를 생성하는 스크립트에 다음과 같이 전달할 수 있습니다.

string script = string.Format(@" 
<script type='text/javascript'> 
function updatePushPin() { 
map.entities.clear(); 
map.setView({zoom: 12, center: new Microsoft.Maps.Location(document.getElementById('{0}').text, document.getElementById('{1}').text)}); 

var center = map.getCenter(); 
var pin = new Microsoft.Maps.Pushpin(center); 
map.entities.push(pin); 

} 
</script>", latitude.ClientID, longitude.ClientID); 
+0

죄송합니다. 나는 또한 나의 코드를 바꿨다는 것을 의심했다. 나는 너의 것을 시도했지만 효과가 없다. 위의 코드는 수정 된 코드입니다. –