PlacesService class
google.maps.places.PlacesService
class
Contains methods related to searching for places and retrieving details about a place.
Library
places
| Constructor | |
|---|---|
PlacesService |
PlacesService(attrContainer)Parameters:
Creates a new instance of the PlacesService that renders attributions in the specified container. |
| Methods | |
|---|---|
findPlaceFromPhoneNumber |
findPlaceFromPhoneNumber(request, callback)Parameters:
Return Value: None
Retrieves a list of places based on a phone number. In most cases there should be just one item in the result list, however if the request is ambiguous more than one result may be returned. The PlaceResults passed to the callback are subsets of a full PlaceResult. Your app can get a more detailed PlaceResult for each place by calling PlacesService.getDetails and passing the PlaceResult.place_id for the desired place. |
findPlaceFromQuery |
findPlaceFromQuery(request, callback)Parameters:
Return Value: None
Retrieves a list of places based on a query string. In most cases there should be just one item in the result list, however if the request is ambiguous more than one result may be returned. The PlaceResults passed to the callback are subsets of a full PlaceResult. Your app can get a more detailed PlaceResult for each place by calling PlacesService.getDetails and passing the PlaceResult.place_id for the desired place. |
getDetails |
getDetails(request, callback)Parameters:
Return Value: None
Retrieves details about the place identified by the given placeId. |
nearbySearch |
nearbySearch(request, callback)Parameters:
Return Value: None
Retrieves a list of places near a particular location, based on keyword or type. Location must always be specified, either by passing a LatLngBounds, or location and radius parameters. The PlaceResults passed to the callback are subsets of the full PlaceResult. Your app can get a more detailed PlaceResult for each place by sending a Place Details request passing the PlaceResult.place_id for the desired place. The PlaceSearchPagination object can be used to fetch additional pages of results (null if this is the last page of results or if there is only one page of results). |
textSearch |
textSearch(request, callback)Parameters:
Return Value: None
Retrieves a list of places based on a query string (for example, "pizza in New York", or "shoe stores near Ottawa"). Location parameters are optional; when the location is specified, results are only biased toward nearby results rather than restricted to places inside the area. Use textSearch when you want to search for places using an arbitrary string, and in cases where you may not want to restrict search results to a particular location. The PlaceSearchPagination object can be used to fetch additional pages of results (null if this is the last page of results or if there is only one page of results). |
PlaceDetailsRequest interface
google.maps.places.PlaceDetailsRequest
interface
A Place details query to be sent to the PlacesService.
Library
places
| Properties | |
|---|---|
fields |
Type:
Array<string>Fields to be included in the details response. For a list of fields see PlaceResult. Nested fields can be specified with dot-paths (for example, "geometry.location"). |
placeId |
Type:
stringThe Place ID of the Place for which details are being requested. |
sessionToken |
Type:
AutocompleteSessionTokenUnique reference used to bundle the details request with an autocomplete session. |
FindPlaceFromPhoneNumberRequest interface
google.maps.places.FindPlaceFromPhoneNumberRequest
interface
A find place from text search request to be sent to PlacesService.findPlaceFromPhoneNumber.
Library
places
| Properties | |
|---|---|
fields |
Type:
Array<string>Fields to be included in the response. For a list of fields see PlaceResult. Nested fields can be specified with dot-paths (for example, "geometry.location"). |
locationBias |
Type:
LocationBiasThe bias used when searching for Place. The result will be biased towards, but not restricted to, the given LocationBias. |
phoneNumber |
Type:
stringThe phone number of the place to look up. Format must be E.164. |
FindPlaceFromQueryRequest interface
google.maps.places.FindPlaceFromQueryRequest
interface
A find place from text search request to be sent to PlacesService.findPlaceFromQuery.
Library
places
| Properties | |
|---|---|
locationBias |
Type:
LocationBiasThe bias used when searching for Place. The result will be biased towards, but not restricted to, the given LocationBias. |
query |
Type:
stringThe request's query. For example, the name or address of a place. |
PlaceSearchRequest interface
google.maps.places.PlaceSearchRequest
interface
A Place search query to be sent to the PlacesService.
Library
places
| Properties | |
|---|---|
bounds |
The bounds within which to search for Places. Both location and radius will be ignored if bounds is set. |
keyword |
Type:
stringA 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 |
Type:
LatLng|LatLngLiteralThe location around which to search for Places. |
maxPriceLevel |
Type:
numberRestricts results to only those places at the specified price level or lower. Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. Must be greater than or equal to minPrice , if specified. |
minPriceLevel |
Type:
numberRestricts results to only those places at the specified price level or higher. Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. Must be less than or equal to maxPrice, if specified. |
name |
Type:
stringRestricts the Place search results to Places that include this text in the name. |
openNow |
Type:
booleanRestricts results to only those places that are open right now. |
radius |
Type:
numberThe distance from the given location within which to search for Places, in meters. The maximum allowed value is 50 000. |
rankBy |
Type:
RankBySpecifies the ranking method to use when returning results. Defaults to PROMINENCE. Note that when rankBy is set to DISTANCE, you must specify a location but you cannot specify a radius or bounds. |
type |
Type:
stringSearches 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. |
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 |
Type:
LatLng|LatLngLiteralThe center of the area used to bias results when searching for Places. |
query |
Type:
stringThe request's query term. For example, 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:
numberThe radius of the area used to bias results when searching for Places, in meters. |
type |
Type:
stringSearches 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. |
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. |
LocationBias typedef
google.maps.places.LocationBias
typedef
A LocationBias represents a soft boundrary or hint to use when searching for Places. Results may come from outside the specified area. To use the current user's IP address as a bias, the string "IP_BIAS" can be specified. Note: if using a Circle the center and radius must be defined.
Library
places
LatLng|LatLngLiteral|LatLngBounds|LatLngBoundsLiteral|Circle|CircleLiteral|string
PlacesServiceStatus constants
google.maps.places.PlacesServiceStatus
constants
The status returned by the PlacesService on the completion of its searches. Specify these by value, or by using the constant's name. For example, 'OK' or google.maps.places.PlacesServiceStatus.OK.
Library
places
| Constants | |
|---|---|
INVALID_REQUEST |
This request was invalid. |
NOT_FOUND |
The place referenced was not found. |
OK |
The response contains a valid result. |
OVER_QUERY_LIMIT |
The application has gone over its request quota. |
REQUEST_DENIED |
The application is not allowed to use the PlacesService. |
UNKNOWN_ERROR |
The PlacesService request could not be processed due to a server error. The request may succeed if you try again. |
ZERO_RESULTS |
No result was found for this request. |
PlaceSearchPagination interface
google.maps.places.PlaceSearchPagination
interface
An object used to fetch additional pages of Places results.
Library
places
| Methods | |
|---|---|
nextPage |
nextPage()Parameters: None
Return Value: None
Fetches the next page of results. Uses the same callback function that was provided to the first search request. |
| Properties | |
|---|---|
hasNextPage |
Type:
booleanIndicates if further results are available. true when there is an additional results page. |
PlaceResult interface
google.maps.places.PlaceResult
interface
Defines information about a Place.
Library
places
| Properties | |
|---|---|
address_components |
Type:
Array<GeocoderAddressComponent>The collection of address components for this Place's location. Only available with PlacesService.getDetails. |
adr_address |
Type:
stringThe representation of the Place's address in the adr microformat. Only available with PlacesService.getDetails. |
aspects |
Type:
Array<PlaceAspectRating>The rated aspects of this Place, based on Google and Zagat user reviews. The ratings are on a scale of 0 to 30. |
formatted_address |
Type:
stringThe Place's full address. |
formatted_phone_number |
Type:
stringThe Place's phone number, formatted according to the number's regional convention. Only available with PlacesService.getDetails. |
geometry |
Type:
PlaceGeometryThe Place's geometry-related information. |
html_attributions |
Type:
Array<string>Attribution text to be displayed for this Place result. Available html_attributions are always returned regardless of what fields have been requested, and must be displayed. |
icon |
Type:
stringURL to an image resource that can be used to represent this Place's category. |
international_phone_number |
Type:
stringThe Place's phone number in international format. International format includes the country code, and is prefixed with the plus (+) sign. Only available with PlacesService.getDetails. |
name |
Type:
stringThe Place's name. Note: In the case of user entered Places, this is the raw text, as typed by the user. Please exercise caution when using this data, as malicious users may try to use it as a vector for code injection attacks (See http://en.wikipedia.org/wiki/Code_injection). |
opening_hours |
Type:
PlaceOpeningHoursDefines when the Place opens or closes. |
permanently_closed |
Type:
booleanA flag indicating whether the Place is permanently closed. If the Place is not permanently closed, the flag is not present in search or details responses. |
photos |
Type:
Array<PlacePhoto>Photos of this Place. The collection will contain up to ten PlacePhoto objects. |
place_id |
Type:
stringA unique identifier for the Place. |
plus_code |
Type:
PlacePlusCodeDefines Open Location Codes or "plus codes" for the Place. |
price_level |
Type:
numberThe price level of the Place, on a scale of 0 to 4. Price levels are interpreted as follows:
|
rating |
Type:
numberA rating, between 1.0 to 5.0, based on user reviews of this Place. |
reviews |
Type:
Array<PlaceReview>A list of reviews of this Place. Only available with PlacesService.getDetails. |
types |
Type:
Array<string>An array of types for this Place (for example, ["political", "locality"] or ["restaurant", "establishment"]). |
url |
Type:
stringURL of the official Google page for this place. This is the Google-owned page that contains the best available information about the Place. Only available with PlacesService.getDetails. |
utc_offset |
Type:
numberThe offset from UTC of the Place's current timezone, in minutes. For example, Sydney, Australia in daylight savings is 11 hours ahead of UTC, so the utc_offset will be 660. For timezones behind UTC, the offset is negative. For example, the is -60 for Cape Verde. Only available with PlacesService.getDetails. |
vicinity |
Type:
stringThe simplified address for the Place, including the street name, street number, and locality, but not the province/state, postal code, or country. For example, Google's Sydney, Australia office has a vicinity value of "48 Pirrama Road, Pyrmont". Only available with PlacesService.getDetails. |
website |
Type:
stringThe authoritative website for this Place, such as a business' homepage. Only available with PlacesService.getDetails. |
PlaceAspectRating interface
google.maps.places.PlaceAspectRating
interface
Defines information about an aspect of the place that users have reviewed.
Library
places
| Properties | |
|---|---|
rating |
Type:
numberThe rating of this aspect. For individual reviews this is an integer from 0 to 3. For aggregated ratings of a place this is an integer from 0 to 30. |
type |
Type:
stringThe aspect type. For example, "food", "decor", "service", or "overall". |
PlaceGeometry interface
google.maps.places.PlaceGeometry
interface
Defines information about the geometry of a Place.
Library
places
| Properties | |
|---|---|
location |
Type:
LatLngThe Place's position. |
viewport |
Type:
LatLngBoundsThe preferred viewport when displaying this Place on a map. This property will be null if the preferred viewport for the Place is not known. Only available with PlacesService.getDetails. |
PlaceOpeningHours interface
google.maps.places.PlaceOpeningHours
interface
Defines information about the opening hours of a Place.
Library
places
| Properties | |
|---|---|
open_now |
Type:
booleanWhether the Place is open at the current time. |
periods |
Type:
Array<PlaceOpeningHoursPeriod>Opening periods covering for each day of the week, starting from Sunday, in chronological order. Days in which the Place is not open are not included. Only available with PlacesService.getDetails. |
weekday_text |
Type:
Array<string>An array of seven strings representing the formatted opening hours for each day of the week. The Places Service will format and localize the opening hours appropriately for the current language. The ordering of the elements in this array depends on the language. Some languages start the week on Monday while others start on Sunday. Only available with PlacesService.getDetails. Other calls may return an empty array. |
PlaceOpeningHoursPeriod interface
google.maps.places.PlaceOpeningHoursPeriod
interface
Defines structured information about the opening hours of a Place. Note: If a Place is always open, the close section will be missing from the response. Clients can rely on always-open being represented as an open period containing day with value 0 and time with value "0000", and no close.
Library
places
| Properties | |
|---|---|
close |
Type:
PlaceOpeningHoursTimeThe closing time for the Place. |
open |
Type:
PlaceOpeningHoursTimeThe opening time for the Place. |
PlaceOpeningHoursTime interface
google.maps.places.PlaceOpeningHoursTime
interface
Defines when a Place opens or closes.
Library
places
| Properties | |
|---|---|
day |
Type:
numberThe days of the week, as a number in the range [ 0, 6], starting on Sunday. For example, 2 means Tuesday. |
time |
Type:
stringThe time of day in 24-hour "hhmm" format. Values are in the range [ "0000", "2359"]. The time will be reported in the Place’s time zone. |
PlacePlusCode interface
google.maps.places.PlacePlusCode
interface
Defines Open Location Codes or "plus codes" for a Place. Plus codes can be used as a replacement for street addresses in places where they do not exist (where buildings are not numbered or streets are not named).
Library
places
| Properties | |
|---|---|
compound_code |
Type:
stringA plus code with a 1/8000th of a degree by 1/8000th of a degree area where the first four characters (the area code) are dropped and replaced with a locality description. For example, "9G8F+5W Zurich, Switzerland". If no suitable locality that can be found to shorten the code then this field is omitted. |
global_code |
Type:
stringA plus code with a 1/8000th of a degree by 1/8000th of a degree area. For example, "8FVC9G8F+5W". |
PlacePhoto interface
google.maps.places.PlacePhoto
interface
Represents a photo element of a Place.
Library
places
| Methods | |
|---|---|
getUrl |
getUrl(opts)Parameters:
Return Value:
stringReturns the image URL corresponding to the specified options. You must include a PhotoOptions object with at least one of maxWidth or maxHeight specified. |
| Properties | |
|---|---|
height |
Type:
numberThe height of the photo in pixels. |
html_attributions |
Type:
Array<string>Attribution text to be displayed for this photo. |
width |
Type:
numberThe width of the photo in pixels. |
PhotoOptions interface
google.maps.places.PhotoOptions
interface
Defines photo-requesting options.
Library
places
| Properties | |
|---|---|
maxHeight |
Type:
numberThe maximum height in pixels of the returned image. |
maxWidth |
Type:
numberThe maximum width in pixels of the returned image. |
PlaceReview interface
google.maps.places.PlaceReview
interface
Represents a single review of a place.
Library
places
| Properties | |
|---|---|
aspects |
Type:
Array<PlaceAspectRating>The aspects rated by the review. The ratings on a scale of 0 to 3. |
author_name |
Type:
stringThe name of the reviewer. |
author_url |
Type:
stringA link to the reviewer's profile. This will be undefined when the reviewer's profile is unavailable. |
language |
Type:
stringAn IETF language code indicating the language in which this review is written. Note that this code includes only the main language tag without any secondary tag indicating country or region. For example, all the English reviews are tagged as 'en' rather than 'en-AU' or 'en-UK'. |
text |
Type:
stringThe text of a review. |