Is there a way to make Google Map’s autocomplete restrict results to, say, just within a state? It seems that it can only be restricted by country: https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions.
If there is no way to do it with Google’s autocomplete, is there a jQuery plugin that will do this for me? I need a good autocomplete plugin that will hopefully return the entire map API response (or at least lat/lng vallues).
You have the option of setting
boundsrather than usingComponent Restrictionswhen you construct theAutocomplete. It is described in the Autocomplete section of the Developer’s Guide and coding specifications are defined in the AutocompleteOptions entry in the API Doc. You may also change the bounds after theAutocompletehas been created by calling:autocomplete.setBounds(bounds).The
boundsaren’t guaranteed to limit results to results within the bounds, but setting theboundsto the area that covers a state or city will come very close to achieving what you describe.If you need to go further, you also have the option of switching from the
Autocompleteto using the Places Librarydev-guide, which also allows you to define therankByoptional property. If you use thegoogle.maps.places.RankBy.DISTANCEto definerankBy, you get added control over limiting the results returned to a specific geographic area. These are about the best options currently available on Google Maps.