Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make my Google Maps api v3 address search bar work by hitting the enter button on the keyboard?
    primarykey
    data
    text
    <p>I'm developing a webpage and I would just like to make something more user friendly. I have a functional Google Maps api v3 and an address search bar. Currently, I have to use the mouse to select search to initialize the geocoding function. How can I make the map return a placemark by hitting the enter button on my keyboard and by clicking the search button? I just want to make it as user-friendly as possible.</p> <p>Here is the javascript and div, respectively, I created for the address bar: </p> <pre><code>var geocoder; function initialize() { geocoder = new google.maps.Geocoder (); function codeAddress () { var address = document.getElementById ("address").value; geocoder.geocode ( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results [0].geometry.location); marker.setPosition(results [0].geometry.location); map.setZoom(14); } else { alert("Geocode was not successful for the following reason: " + status); } }); } function initialize() { document.getElementById("address").focus(); } function setFocusOnSearch() { document.getElementById("search").focus(); } function codeAddress() { document.getElementById("address").focus(); } &lt;body onload="initialize()"&gt; &lt;div id="geocoder"&gt; &lt;input id="address" type="textbox" value="" "onblur="setFocusOnSearch()"&gt; &lt;input id="search" type="button" value="Search" onclick="codeAddress()"&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>Thank you in advance for your help</p> <p><img src="https://i.stack.imgur.com/vmlpr.jpg" alt="enter image description here"></p>
    singulars
    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.
 

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