Skip to content Skip to sidebar Skip to footer

Initial Place For Google Place Autocomplete

I am using google map place autocomplete API in my application. Now at the initial load i want to show one location on that input of autocomplete. Is there any way i can achieve it

Solution 1:

Probably the API doesn't support anything like that. However, you can simulate the same by prefilling the text box with the location you want and then center your map on that location.

For example: You can prefill the textbox with 'Bangalore, Karnataka' and center the map at 12.970786, 77.593466 (Lat and Lng of Bangalore).

Solution 2:

If you already know the result of the auto complete, use that address/place and use either the geocoder, the places API or the resulting coordinates go display the result.

Although looking at your fiddle, I think this is what you are looking for (fill in the Autocomplete input with the predefined value of "Nebraska, United States":

<inputid="autocomplete" placeholder="Enter location"type="text" value="Nebraska, United States" />

proof of concept fiddle

code snippet:

functioninitialize() {

  new google.maps.places.Autocomplete(
    (document.getElementById('autocomplete')), {
      types: ['geocode']
    });
}

initialize();
#autocomplete {
  width: 300px;
  padding: 7px;
}
<scriptsrc="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script><inputid="autocomplete"placeholder="Enter location"type="text"value="Nebraska, United States" />

Post a Comment for "Initial Place For Google Place Autocomplete"