AI-generated Key Takeaways
-
The Places fields
opening_hours.open_nowandutc_offsetare deprecated and will be turned off on February 20, 2021 in the Places Library, Maps JavaScript API. -
For Place Details requests, use the
opening_hours.isOpen()method and includeopening_hoursandutc_offset_minutesin thefieldsrequest parameter instead ofopening_hours.open_nowandutc_offset. -
For Find Place requests, it is recommended to make a Place Details request to get
opening_hoursinformation. -
For Nearby Search and Text Search requests, use the
openNowrequest parameter to filter results based on open/closed status. -
Replace
utc_offsetwithutc_offset_minutesin Place Details requests for the UTC offset information.
The Places fields opening_hours.open_now and utc_offset are deprecated as
of November 20, 2019, and will be turned off on
February 20, 2021. These fields are deprecated ONLY in the
Places Library, Maps JavaScript API. This guide shows you how to update your code to
stop using these fields.
opening_hours.open_now field
This section shows how to update this functionality for each type of Places request.
Place Details requests
The opening_hours.open_now field is replaced by the
opening_hours.isOpen()
method.
For Place Details requests,
instead of requesting opening_hours.open_now in the fields request
parameter, include opening_hours and utc_offset_minutes in the fields
request parameter, then call the opening_hours.isOpen() method on the returned
google.maps.places.PlaceResult object to check whether the place is open. The
following example shows a Place Details request that determines whether a place
is open:
new google.maps.places.PlacesService(attrContainer).getDetails({
placeId: '...',
fields: ['opening_hours','utc_offset_minutes'],
}, function (place, status) {
if (status !== 'OK') return; // something went wrong
const isOpenAtTime = place.opening_hours.isOpen(new Date('December 17, 2020 03:24:00'));
if (isOpenAtTime) {
// We know it's open.
}
const isOpenNow = place.opening_hours.isOpen();
if (isOpenNow) {
// We know it's open.
}
});
Find Place requests
For Find Place requests,
there is no replacement for the opening_hours.open_now field. We recommend
making a Place Details request
to get opening_hours information.
Nearby Search & Text Search requests
For Nearby Search and Text Search requests, you can use the openNow
request parameter, which has the effect of filtering results to include only
places that are currently open.
openNow:falsereturns all places.openNow:truereturns only places that are currently open.
To list all places AND indicate openNow status, first make a request using
openNow:false to get all places, then make a request using openNow:true to
get open places only. Then, merge the responses.
utc_offset field
In Place Details requests, the utc_offset field is replaced by the
utc_offset_minutes field. Simply replace occurrences of utc_offset with
utc_offset_minutes in the fields request parameter, and when reading this
information from PlaceResult.