New pricing changes went into effect on July 16, 2018. For more information, check out the Guide for Existing Users.

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.
getFields
getFields()
Parameters:  None
Return Value:  Array<string>|undefined
Returns the fields to be included for the Place in the details response when the details are successfully retrieved. For a list of fields see PlaceResult.
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. For example, the country.
setFields
setFields(fields)
Parameters: 
  • fieldsArray<string>|undefined
Return Value:  None
Sets the fields to be included for the Place in the details response when the details are successfully retrieved. For a list of fields see PlaceResult.
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. For example, the country.
fields
Type:  Array<string>
Fields to be included for the Place in the details response when the details are successfully retrieved. For a list of fields see PlaceResult. Nested fields can be specified with dot-paths (for example, "geometry.location").
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.

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.

다음에 대한 의견 보내기...

Maps JavaScript API
도움이 필요하시나요? 지원 페이지를 방문하세요.