Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps API Auto Complete
    primarykey
    data
    text
    <p>I am attempting use Google Maps API to create two auto complete input boxes along with a map to mark the positions. </p> <p>Currently based on the examples in the Docs I have got a single input box which works with auto-complete and places a marker on the map, however I would now like to expand on this and have a second input box with does the same thing on the <strong>same map</strong>, but having trouble achieving it.</p> <p>The code so far is</p> <pre><code>&lt;script type="text/javascript"&gt; function initialize() { var mapOptions = { center: new google.maps.LatLng(-33.8688, 151.2195), zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map'), mapOptions); var input = document.getElementById('frombox'); var autocomplete = new google.maps.places.Autocomplete(input); autocomplete.bindTo('bounds', map); var infowindow = new google.maps.InfoWindow(); var marker = new google.maps.Marker({ map: map }); google.maps.event.addListener(autocomplete, 'place_changed', function() { infowindow.close(); var place = autocomplete.getPlace(); if (place.geometry.viewport) { map.fitBounds(place.geometry.viewport); } else { map.setCenter(place.geometry.location); map.setZoom(15); } var image = new google.maps.MarkerImage( place.icon, new google.maps.Size(71, 71), new google.maps.Point(0, 0), new google.maps.Point(17, 34), new google.maps.Size(35, 35)); marker.setIcon(image); marker.setPosition(place.geometry.location); var address = ''; if (place.address_components) { address = [(place.address_components[0] &amp;&amp; place.address_components[0].short_name || ''), (place.address_components[1] &amp;&amp; place.address_components[1].short_name || ''), (place.address_components[2] &amp;&amp; place.address_components[2].short_name || '') ].join(' '); } infowindow.setContent('&lt;div&gt;&lt;strong&gt;' + place.name + '&lt;/strong&gt;&lt;br&gt;' + address); infowindow.open(map, marker); }); // Sets a listener on a radio button to change the filter type on Places // Autocomplete. function setupClickListener(id, types) { var radioButton = document.getElementById(id); google.maps.event.addDomListener(radioButton, 'click', function() { autocomplete.setTypes(types); }); } setupClickListener('changetype-all', []); setupClickListener('changetype-establishment', ['establishment']); setupClickListener('changetype-geocode', ['geocode']); } google.maps.event.addDomListener(window, 'load', initialize); &lt;/script&gt; </code></pre> <p>Could anyone help me set up the second input box called #tobox to do the same thing on the same map, I would really appreciate it.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload