You're all set!

To start developing, please head over to our developer documentation.

Activate the Google Maps JavaScript API

To get you started we'll guide you through the Google Developers Console to do a few things first:

  1. Create or choose a project
  2. Activate the Google Maps JavaScript API and related services
  3. Create appropriate keys
Continue

Places Widgets

Autocomplete class

google.maps.places.Autocomplete class

A widget that provides Place predictions based on a user's text input. It attaches to an input element of type text, and listens for text entry in that field. The list of predictions is presented as a drop-down list, and is updated as text is entered.

This class extends MVCObject.

Library

places

Constructor
Autocomplete
Autocomplete(inputField[, opts])
Parameters: 
Creates a new instance of Autocomplete that attaches to the specified input text field with the given options.
Methods
getBounds
getBounds()
Parameters:  None
Return Value:  LatLngBounds|undefined
Returns the bounds to which predictions are biased.
getPlace
getPlace()
Parameters:  None
Return Value:  PlaceResult
Returns the details of the Place selected by user if the details were successfully retrieved. Otherwise returns a stub Place object, with the name property set to the current value of the input field.
setBounds
setBounds(bounds)
Parameters: 
Return Value:  None
Sets the preferred area within which to return Place results. Results are biased towards, but not restricted to, this area.
setComponentRestrictions
setComponentRestrictions(restrictions)
Parameters: 
Return Value:  None
Sets the component restrictions. Component restrictions are used to restrict predictions to only those within the parent component. E.g., the country.
setOptions
setOptions(options)
Parameters: 
Return Value:  None
setTypes
setTypes(types)
Parameters: 
  • typesArray<string>
Return Value:  None
Sets the types of predictions to be returned. For a list of supported types, see the developer's guide. If no type is specified, all types will be returned. The setTypes method accepts a single element array.
Events
place_changed
function()
Arguments:  None
This event is fired when a PlaceResult is made available for a Place the user has selected.
If the user enters the name of a Place that was not suggested by the control and presses the Enter key, or if a Place Details request fails, the PlaceResult contains the user input in the name property, with no other properties defined.

AutocompleteOptions interface

google.maps.places.AutocompleteOptions interface

The options that can be set on an Autocomplete object.

Library

places

Properties
bounds
The area in which to search for places.
componentRestrictions
The component restrictions. Component restrictions are used to restrict predictions to only those within the parent component. E.g., the country.
placeIdOnly
Type:  boolean
Whether to retrieve only Place IDs. The PlaceResult made available when the place_changed event is fired will only have the place_id, types and name fields, with the place_id, types and description returned by the Autocomplete service. Disabled by default.
strictBounds
Type:  boolean
A boolean value, indicating that the Autocomplete widget should only return those places that are inside the bounds of the Autocomplete widget at the time the query is sent. Setting strictBounds to false (which is the default) will make the results biased towards, but not restricted to, places contained within the bounds.
types
Type:  Array<string>
The types of predictions to be returned. For a list of supported types, see the developer's guide. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the 'geocode' and 'establishment' types, but note that this will have the same effect as specifying no types.

AutocompletePrediction interface

google.maps.places.AutocompletePrediction interface

Represents a single autocomplete prediction.

Library

places

Properties
description
Type:  string
This is the unformatted version of the query suggested by the Places service.
matched_substrings
Type:  Array<PredictionSubstring>
A set of substrings in the place's description that match elements in the user's input, suitable for use in highlighting those substrings. Each substring is identified by an offset and a length, expressed in unicode characters.
place_id
Type:  string
A place ID that can be used to retrieve details about this place using the place details service (see PlacesService.getDetails).
terms
Type:  Array<PredictionTerm>
Information about individual terms in the above description, from most to least specific. For example, "Taco Bell", "Willitis", and "CA".
types
Type:  Array<string>
An array of types that the prediction belongs to, for example 'establishment' or 'geocode'.

PredictionTerm interface

google.maps.places.PredictionTerm interface

Represents a prediction term.

Library

places

Properties
offset
Type:  number
The offset, in unicode characters, of the start of this term in the description of the place.
value
Type:  string
The value of this term, e.g. "Taco Bell".

PredictionSubstring interface

google.maps.places.PredictionSubstring interface

Represents a prediction substring.

Library

places

Properties
length
Type:  number
The length of the substring.
offset
Type:  number
The offset to the substring's start within the description string.

AutocompleteService class

google.maps.places.AutocompleteService class

Contains methods related to retrieving Autocomplete predictions.

Library

places

Constructor
AutocompleteService
AutocompleteService()
Parameters:  None
Creates a new instance of the AutocompleteService.
Methods
getPlacePredictions
getPlacePredictions(request, callback)
Parameters: 
Return Value:  None
Retrieves place autocomplete predictions based on the supplied autocomplete request.
getQueryPredictions
getQueryPredictions(request, callback)
Parameters: 
Return Value:  None
Retrieves query autocomplete predictions based on the supplied query autocomplete request.

AutocompletionRequest interface

google.maps.places.AutocompletionRequest interface

An Autocompletion request to be sent to the AutocompleteService.

Library

places

Properties
bounds
Bounds for prediction biasing. Predictions will be biased towards, but not restricted to, the given bounds. Both location and radius will be ignored if bounds is set.
componentRestrictions
The component restrictions. Component restrictions are used to restrict predictions to only those within the parent component. E.g., the country.
input
Type:  string
The user entered input string.
location
Type:  LatLng
Location for prediction biasing. Predictions will be biased towards the given location and radius. Alternatively, bounds can be used.
offset
Type:  number
The character position in the input term at which the service uses text for predictions (the position of the cursor in the input field).
radius
Type:  number
The radius of the area used for prediction biasing. The radius is specified in meters, and must always be accompanied by a location property. Alternatively, bounds can be used.
types
Type:  Array<string>
The types of predictions to be returned. For a list of supported types, see the developer's guide. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the 'geocode' and 'establishment' types, but note that this will have the same effect as specifying no types.

ComponentRestrictions interface

google.maps.places.ComponentRestrictions interface

Defines the component restrictions that can be used with the autocomplete service.

Library

places

Properties
country
Type:  string|Array<string>
Restricts predictions to the specified country (ISO 3166-1 Alpha-2 country code, case insensitive). E.g., us, br, au. You can provide a single one, or an array of up to 5 country code strings.

QueryAutocompletePrediction interface

google.maps.places.QueryAutocompletePrediction interface

Represents a single Query Autocomplete prediction.

Library

places

Properties
description
Type:  string
This is the unformatted version of the query suggested by the Places service.
matched_substrings
Type:  Array<PredictionSubstring>
A set of substrings in the place's description that match elements in the user's input, suitable for use in highlighting those substrings. Each substring is identified by an offset and a length, expressed in unicode characters.
place_id
Type:  string
Only available if prediction is a place. A place ID that can be used to retrieve details about this place using the place details service (see PlacesService.getDetails).
terms
Type:  Array<PredictionTerm>
Information about individual terms in the above description. Categorical terms come first (e.g., "restaurant"). Address terms appear from most to least specific. For example, "San Francisco", and "CA".

QueryAutocompletionRequest interface

google.maps.places.QueryAutocompletionRequest interface

An QueryAutocompletion request to be sent to the QueryAutocompleteService.

Library

places

Properties
bounds
Bounds for prediction biasing. Predictions will be biased towards, but not restricted to, the given bounds. Both location and radius will be ignored if bounds is set.
input
Type:  string
The user entered input string.
location
Type:  LatLng
Location for prediction biasing. Predictions will be biased towards the given location and radius. Alternatively, bounds can be used.
offset
Type:  number
The character position in the input term at which the service uses text for predictions (the position of the cursor in the input field).
radius
Type:  number
The radius of the area used for prediction biasing. The radius is specified in meters, and must always be accompanied by a location property. Alternatively, bounds can be used.

RadarSearchRequest interface

google.maps.places.RadarSearchRequest interface

A Radar Search request to be sent to the PlacesService.

Library

places

Properties
bounds
Bounds used to bias results when searching for Places (optional). Both location and radius will be ignored if bounds is set. Results will not be restricted to those inside these bounds; but, results inside it will rank higher.
keyword
Type:  string
A term to be matched against all available fields, including but not limited to name, type, and address, as well as customer reviews and other third-party content.
location
The center of the area used to bias results when searching for Places.
name
Type:  string
Restricts results to Places that include this text in the name.
radius
Type:  number
The radius of the area used to bias results when searching for Places, in meters.
type
Type:  string
Searches for places of the given type. The type will be translated to the local language of the request's target location and used as query. If a query is also provided, it will be concatenated to the localized type string. Results of a different type will be dropped from the response. Use this to search for language and region independent categorical search. here.

RankBy constants

google.maps.places.RankBy constants

Ranking options for a PlaceSearchRequest.

Library

places

Constants
DISTANCE Ranks place results by distance from the location.
PROMINENCE Ranks place results by their prominence.

google.maps.places.SearchBox class

A widget that provides query predictions based on a user's text input. It attaches to an input element of type text, and listens for text entry in that field. The list of predictions is presented as a drop-down list, and is updated as text is entered.

This class extends MVCObject.

Library

places

Constructor
SearchBox
SearchBox(inputField[, opts])
Parameters: 
Creates a new instance of SearchBox that attaches to the specified input text field with the given options.
Methods
getBounds
getBounds()
Parameters:  None
Return Value:  LatLngBounds
Returns the bounds to which query predictions are biased.
getPlaces
getPlaces()
Parameters:  None
Return Value:  Array<PlaceResult>
Returns the query selected by the user, or null if no places have been found yet, to be used with places_changed event.
setBounds
setBounds(bounds)
Parameters: 
Return Value:  None
Sets the region to use for biasing query predictions. Results will only be biased towards this area and not be completely restricted to it.
Events
places_changed
function()
Arguments:  None
This event is fired when the user selects a query, getPlaces should be used to get new places.

SearchBoxOptions interface

google.maps.places.SearchBoxOptions interface

The options that can be set on a SearchBox object.

Library

places

Properties
bounds
The area towards which to bias query predictions. Predictions are biased towards, but not restricted to, queries targeting these bounds.

TextSearchRequest interface

google.maps.places.TextSearchRequest interface

A text search request to be sent to the PlacesService.

Library

places

Properties
bounds
Bounds used to bias results when searching for Places (optional). Both location and radius will be ignored if bounds is set. Results will not be restricted to those inside these bounds; but, results inside it will rank higher.
location
The center of the area used to bias results when searching for Places.
query
Type:  string
The request's query term. e.g. the name of a place ('Eiffel Tower'), a category followed by the name of a location ('pizza in New York'), or the name of a place followed by a location disambiguator ('Starbucks in Sydney').
radius
Type:  number
The radius of the area used to bias results when searching for Places, in meters.
type
Type:  string
Searches for places of the given type. The type is translated to the local language of the request's target location and used as a query string. If a query is also provided, it is concatenated to the localized type string. Results of a different type are dropped from the response. Use this field to perform language and region independent categorical searches. Valid types are given here.

Send feedback about...

Google Maps JavaScript API
Google Maps JavaScript API
Need help? Visit our support page.