简体   繁体   中英

google map api v2

I've problem calling gdrirection.load(),if I specified the values it'll work ,but if I pass them through text boxes it doesn't work. here's my code

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

Thanks

In your code you are passing TextBox1 as from address and txtAddress as to address. So google is not able to understand the both address.Use the following code to pass values from textboxes:

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

This one will work fine.Hope this helps you :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM