1.11M Members

Entering custom address into embedded Google Maps

 
0
 

Hi All. I am using Microsoft Visual Web Developer 2010. I have embedded google maps into my webpage. I am using 4 textboxes: Street, City, Province and Postal Code. The user will enter these details then it will get put into a string variable like this string location = street + "," + "city" + "," + province + "," + postCode;

Now the google API code below uses this line for input: var input = document.getElementById('TextBox1');
I tried using var input = location; but it picked up syntax error. What can I do to fix this? Thanks.

Here is the source code below:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<script type="text/javascript">

    function Initialize() {

        var mapOptions = {
            center: new google.maps.LatLng(-33.01, 27.9),
            zoom: 13,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById('GMap1'), mapOptions);

        **var input = document.getElementById('TextBox1');**
        var autocomplete = new google.maps.places.Autocomplete(input);
        autocomplete.bindTo('bounds', map);

        google.maps.event.addListener(autocomplete, 'place_changed', function () {

            var place = autocomplete.getPlace();
            if (place.geometry.viewport) {
                map.fitBounds(place.geometry.viewport);
            } else {
                map.setCenter(place.geometry.location);
                map.setZoom(17);
            }
        });

    }
    google.maps.event.addDomListener(window, 'load', Initialize);

</script>

<input type="text" id="TextBox1">
        <div id="GMap1" style="height: 240px; width:570px" ></div>
 
-1
 

Shouldn't you be passing input.value ?

 
0
 

Yeah thanks that worked

Question Answered as of 10 Months Ago by pritaeas
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: