地点字段迁移(open_now、utc_offset)
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
“地点”字段 opening_hours.open_now
和 utc_offset
自 2019 年 11 月 20 日起弃用,自 2021 年 2 月 20 日起停用。这两个字段仅在 Maps JavaScript API 地点库中弃用。本指南介绍了如何更新代码以停止使用这两个字段。
opening_hours.open_now
字段
本部分介绍了如何针对各个类型的“地点”请求,更新此功能。
“地点详情”请求
opening_hours.open_now
字段已替换为 opening_hours.isOpen()
方法。
对于“地点详情”请求,请在 fields
请求参数中包含 opening_hours
和 utc_offset_minutes
(而不是在 fields
请求参数中请求 opening_hours.open_now
),然后对返回的 google.maps.places.PlaceResult
对象调用 opening_hours.isOpen()
方法,以检查相应地点是否营业。下例展示了用于确定地点是否营业的“地点详情”请求:
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.
}
});
“查找地点”请求
对于“查找地点”请求,opening_hours.open_now
字段没有替代项。建议您发出“地点详情”请求以获取 opening_hours
信息。
“附近搜索”请求和“文本搜索”请求
对于“附近搜索”请求和“文本搜索”请求,您可以使用 openNow
请求参数,该参数的作用是过滤结果,使其仅包含当前营业的地点。
openNow:false
会返回所有地点。
openNow:true
仅返回当前营业的地点。
若要列出所有地点并指示 openNow
状态,请先使用 openNow:false
发出请求,获取所有地点,然后使用 openNow:true
发出请求,仅获取正在营业的地点。然后合并响应。
utc_offset
字段
在“地点详情”请求中,utc_offset
字段已替换为 utc_offset_minutes
字段。只需在 fields
请求参数中以及从 PlaceResult
读取此类信息时,将原本的 utc_offset
替换为 utc_offset_minutes
即可。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[[["\u003cp\u003eThe Places fields \u003ccode\u003eopening_hours.open_now\u003c/code\u003e and \u003ccode\u003eutc_offset\u003c/code\u003e are deprecated and will be turned off on February 20, 2021 in the Places Library, Maps JavaScript API.\u003c/p\u003e\n"],["\u003cp\u003eFor Place Details requests, use the \u003ccode\u003eopening_hours.isOpen()\u003c/code\u003e method and include \u003ccode\u003eopening_hours\u003c/code\u003e and \u003ccode\u003eutc_offset_minutes\u003c/code\u003e in the \u003ccode\u003efields\u003c/code\u003e request parameter instead of \u003ccode\u003eopening_hours.open_now\u003c/code\u003e and \u003ccode\u003eutc_offset\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFor Find Place requests, it is recommended to make a Place Details request to get \u003ccode\u003eopening_hours\u003c/code\u003e information.\u003c/p\u003e\n"],["\u003cp\u003eFor Nearby Search and Text Search requests, use the \u003ccode\u003eopenNow\u003c/code\u003e request parameter to filter results based on open/closed status.\u003c/p\u003e\n"],["\u003cp\u003eReplace \u003ccode\u003eutc_offset\u003c/code\u003e with \u003ccode\u003eutc_offset_minutes\u003c/code\u003e in Place Details requests for the UTC offset information.\u003c/p\u003e\n"]]],[],null,["# Place Field Migration (open_now, utc_offset)\n\n\u003cbr /\u003e\n\nThe Places fields `opening_hours.open_now` and `utc_offset` are deprecated as\nof November 20, 2019, and will be turned off on\nFebruary 20, 2021. These fields are deprecated ONLY in the\nPlaces Library, Maps JavaScript API. This guide shows you how to update your code to\nstop using these fields.\n\n`opening_hours.open_now` field\n------------------------------\n\nThis section shows how to update this functionality for each type of Places\nrequest.\n\n### Place Details requests\n\nThe `opening_hours.open_now` field is replaced by the\n[`opening_hours.isOpen()`](/maps/documentation/javascript/reference/places-service#PlaceOpeningHours)\nmethod. \n\nFor [Place Details requests](/maps/documentation/javascript/places#place_details_requests),\ninstead of requesting `opening_hours.open_now` in the `fields` request\nparameter, include `opening_hours` and `utc_offset_minutes` in the `fields`\nrequest parameter, then call the `opening_hours.isOpen()` method on the returned\n`google.maps.places.PlaceResult` object to check whether the place is open. The\nfollowing example shows a Place Details request that determines whether a place\nis open: \n\n new google.maps.places.PlacesService(attrContainer).getDetails({\n placeId: '...',\n fields: ['opening_hours','utc_offset_minutes'],\n }, function (place, status) {\n if (status !== 'OK') return; // something went wrong\n const isOpenAtTime = place.opening_hours.isOpen(new Date('December 17, 2020 03:24:00'));\n if (isOpenAtTime) {\n // We know it's open.\n }\n\n const isOpenNow = place.opening_hours.isOpen();\n if (isOpenNow) {\n // We know it's open.\n }\n });\n\n### Find Place requests\n\nFor [Find Place requests](/maps/documentation/javascript/places#find_place_requests),\nthere is no replacement for the `opening_hours.open_now` field. We recommend\nmaking a [Place Details request](/maps/documentation/javascript/places#place_details_requests)\nto get `opening_hours` information.\n\n### Nearby Search \\& Text Search requests\n\nFor Nearby Search and Text Search requests, you can use the [`openNow`](/maps/documentation/javascript/reference/places-service#PlaceSearchRequest)\nrequest parameter, which has the effect of filtering results to include only\nplaces that are currently open.\n\n- `openNow:false` returns all places.\n- `openNow:true` returns only places that are currently open.\n\nTo list all places AND indicate `openNow` status, first make a request using\n`openNow:false` to get all places, then make a request using `openNow:true` to\nget open places only. Then, merge the responses.\n\n`utc_offset` field\n------------------\n\nIn Place Details requests, the `utc_offset` field is replaced by the\n`utc_offset_minutes` field. Simply replace occurrences of `utc_offset` with\n`utc_offset_minutes` in the `fields` request parameter, and when reading this\ninformation from `PlaceResult`."]]