2012-04-12 154 views
0

我有問題調用gdrirection.load(),如果我指定的值將工作,但如果我通過它們通過文本框它不起作用。 這裏是我的代碼谷歌地圖api v2

var map; 
    var directionsPanel; 
    var directions; 
function initialize() { 

     if (GBrowserIsCompatible()) { 
      map = new GMap2(document.getElementById("map")); 
      map.setCenter(new GLatLng(24.7116667, 46.7241667), 12); 
      map.setUIToDefault(); 
      var txtAddress = document.getElementById('txtAddress').value; 
      var TextBox1 = document.getElementById('TextBox1').value; 
      directions = new GDirections(map, directionsPanel); 
      directions.load("from: 'TextBox1' to: 'txtAddress'");   
     } 
    } 
<body onload=initialize()> 

      <asp:TextBox ID="txtAddress" runat="server" Visible="true" /> 
      <input type="button" value="direction" onclick="initialize();" title="direction" /> 
      <asp:TextBox ID="TextBox1" runat="server" Visible="true"></asp:TextBox>` 

感謝

+0

注[google地圖v2是已棄用](https://developers.google.com/maps/documentation/javascript/v2/) – ManseUK 2012-04-12 09:38:26

回答

1

在你的代碼是路過TextBox1從地址和txtAddress作爲解決。因此谷歌無法瞭解這兩個address.Use下面的代碼從文本框傳遞值:

directions.load("from: "+TextBox1+" to: "+txtAddress+""); 

這一個將工作fine.Hope這可以幫助你:-)

+0

感謝您的回覆,我稍微更改了一些代碼,但仍然無效。 – user1328645 2012-04-12 10:01:17

+0

這是'var txtAddress = document.getElementById(「<%= txtAddress.ClientID%>」); var address = txtAddress.value; var TextBox1 = document.getElementById(「<%= TextBox1.ClientID%>」); var address1 = TextBox1.value; directions = new GDirections(map,directionsPanel); directions.load(「from:」+ TextBox1 +「to:」+ txtAddress +「」);' – user1328645 2012-04-12 10:03:40

+0

一旦檢查您是否將值轉換爲address和address1 vatiables? – Unknown 2012-04-12 10:15:19