2012-11-16 29 views
2

我有一個場景,我必須從數據庫中讀取一些數據,例如已經有經度和緯度信息的地址,然後用標記填充谷歌地圖。我使用Windows窗體和Winform Web瀏覽器控件使用Google地圖。谷歌地圖,winform和捕捉點擊事件

瀏覽器控件顯示一個.asp頁面,其中地址的詳細信息使用查詢字符串傳遞。

要求是,如果用戶點擊谷歌地圖中的任何這些標記,那麼我們應該捕獲單擊事件並處理結果,例如獲取地址的ID,並可能導航到Windows窗體中的特定記錄。

問題是如何捕獲點擊事件,然後將數據從.asp頁面傳遞到窗體?

還有其他更好的可能嗎?建議?

回答

0

這裏是一個另類:

  1. 使用第三方谷歌地圖的控制來完成所有的地圖相關的操作。例如,您可以嘗試GDS Google Map WinForms Control 2.0。只需捕獲MapMarkerMouseClick事件,您就可以輕鬆地在事件處理程序中執行編碼。

  2. 要從.asp頁面傳遞數據,您可能必須自己完成所有操作。這裏是你可能需要一個示例代碼:

    var url = "http://www.google.com"; 
    
        var request = WebRequest.Create(url); 
    
        request.Credentials = CredentialCache.DefaultCredentials; 
    
        var httpResponse = request.GetResponse() as HttpWebResponse; 
    
        if (httpResponse != null) 
        { 
         var status = httpResponse.StatusDescription; 
    
         if (status.ToUpper().Equals("OK")) 
         { 
          var dataStream = httpResponse.GetResponseStream(); 
    
          if (dataStream != null) 
          { 
           var reader = new StreamReader(dataStream); 
    
           var responseFromServer = reader.ReadToEnd(); 
    
           // now you get the whole page, then you need to do your parsing to get the data out 
    
           reader.Close(); 
           reader.Dispose(); 
    
           dataStream.Close(); 
           dataStream.Dispose(); 
          } 
         } 
    
         httpResponse.Close(); 
        }