2014-02-05 31 views
-1

我正在創建一個web應用程序。我希望能夠將Google地圖納入我的一頁中。 從我在其他地方看過的書中,最簡單的想法是將Web瀏覽器放到表單上,但工具箱中沒有「Web瀏覽器」。將asp.net中的Google地圖插入我的網頁

我想要做的是將一個位置插入一個文本框(即倫敦),並插入一種類型的運動(ieCycling)和結果地圖顯示出來。除了使用網絡瀏覽器工具之外,還有其他的方式可以在C#中完成這個工作。

這裏是我的代碼:

protected void btnSearch_Click(object sender, EventArgs e) 
    { 

     string sport = txtSport.Text; 
     string location = txtLocation.Text; 



     try 
     { 
      StringBuilder queryAddrress = new StringBuilder(); 
      queryAddrress.Append("https://maps.google.ie/"); 

      if (sport != string.Empty) 
      { 
       queryAddrress.Append(sport+","+"+"); 


      } 

      if (location != string.Empty) 
      { 
       queryAddrress.Append(location + "," + "+"); 


      } 


      Panel1.Navigate(queryAddrress.ToString()); 


     } 

     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message.ToString(),"Error"); 
     } 


    } protected void btnSearch_Click(object sender, EventArgs e) 
    { 

     string sport = txtSport.Text; 
     string location = txtLocation.Text; 



     try 
     { 
      StringBuilder queryAddrress = new StringBuilder(); 
      queryAddrress.Append("https://maps.google.ie/"); 

      if (sport != string.Empty) 
      { 
       queryAddrress.Append(sport+","+"+"); 


      } 

      if (location != string.Empty) 
      { 
       queryAddrress.Append(location + "," + "+"); 


      } 


      Panel1.Navigate(queryAddrress.ToString()); 


     } 

我試圖把地址轉換成面板,但是這顯然是錯誤的。任何幫助將不勝感激!

回答

1

看起來好像你很混淆並將ASP.NET Web FormsWindows Forms混合。

具體而言,MessageBox.Show()將打開Windows消息框,而不是瀏覽器窗口。而且它會在服務器端發生,無論您的Web服務器運行的是什麼用戶。可能不是所期望的意圖。另外,您不能將「Web瀏覽器」放到頁面上。 Windows窗體有一個WebBrowser控件,它將一個縮小版的Internet Explorer嵌入到Windows應用程序中。但是,再次,可能不是你想要的。

ASP.NET可以像使用普通的HTML網站一樣使用。所以找到一些Google Maps tutorials的HTML,並按照這些。

相關問題