0
<body onload="initialize()">
    <form id="form1" runat="server">
    <div id="map_canvas" style = "width:320px; height:480px">
    </div>
    <div>
        <asp:TextBox ID="address" runat="server"></asp:TextBox>
        <asp:Button Text="find" runat="server" OnClientClick="codeAddress()" />
    </div>
    </form>
</body>

and this is my javascript:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
        var geocoder;
        var map;
        function initialize() {
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(-34.397, 150.644);
            var myOptions = {
                zoom: 8,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        }
        function codeAddress() {
            var address = document.getElementById("<%= address.ClientID %>").value;
            geocoder.geocode({ 'address': address }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
                    });
                } else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            });
        }
    </script>

the codeAddress() function is not working at all ! what's the problem?

10
  • What do you mean with not working at all? Have you set a breakpoint in this function? (IE-Developer-Toolbar / Firebug) Commented May 18, 2011 at 22:57
  • yes, it's not hitting the function ! Commented May 18, 2011 at 22:58
  • now it says Unable to get value of the property 'offsetWidth': object is null or undefined Commented May 18, 2011 at 23:03
  • @Tim it's skipping the geocoder.geocode() in the codeAddress function Commented May 18, 2011 at 23:19
  • @alex: i have no experiences with google's geocoding api and i don't see any obvious error or typo. But maybe here or here is something interesting. Edit: i see, the second link is where you have your code from ;) Commented May 18, 2011 at 23:26

1 Answer 1

0

Try...

document.getElementById("<%= address.ClientID %>")

Change to:

document.getElementById("address").value;
2
  • it's an asp control, so I have to bind it, else the value will change at run-time Commented May 18, 2011 at 23:47
  • Really? (asp, not asp.net?) Are you using master pages or something? Otherwise, you might set the "clientID" property on the control, because that is different that the ID property. Commented May 19, 2011 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.