簡體   English   中英

谷歌地圖API v2

[英]google map api v2

我在調用gdrirection.load()時遇到問題,如果我指定了它將起作用的值,但是如果我將它們通過文本框傳遞,它將不起作用。 這是我的代碼

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>`

謝謝

在您的代碼中,您將TextBox1從address傳遞txtAddress ,將txtAddress傳遞給address。 因此,谷歌無法理解這兩個地址。使用以下代碼從文本框中傳遞值:

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

這個會很好用的,希望對你有幫助:-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM