ย้ายข้อมูลไปยังการค้นหาใกล้เคียง (ใหม่)
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
นักพัฒนาแอปในเขตเศรษฐกิจยุโรป (EEA)
บทนำ
Places API รองรับการค้นหาใกล้เคียง (เดิม)
หากคุณคุ้นเคยกับการค้นหาใกล้เคียง (เดิม)
การค้นหาใกล้เคียง (ใหม่) จะทำการเปลี่ยนแปลงต่อไปนี้
- การค้นหาใกล้เคียง (ใหม่) ใช้คำขอ HTTP แบบ POST
ส่งพารามิเตอร์ในเนื้อหาคำขอหรือในส่วนหัวเป็นส่วนหนึ่งของคำขอ HTTP POST
ในทางตรงกันข้าม เมื่อใช้การค้นหาใกล้เคียง (เดิม)
คุณจะส่งพารามิเตอร์ URL โดยใช้คำขอ HTTP GET
- ต้องมีการมาสก์ฟิลด์ คุณต้องระบุช่องที่ต้องการให้แสดงผล
ในการตอบกลับ ไม่มีรายการฟิลด์ที่แสดงผลเริ่มต้น หากคุณละเว้น
รายการนี้ เมธอดจะแสดงข้อผิดพลาด ดูข้อมูลเพิ่มเติมได้ที่
FieldMask
- การค้นหาใกล้เคียง (ใหม่) รองรับทั้ง
คีย์ API
และโทเค็น OAuth
เป็นกลไกการตรวจสอบสิทธิ์
- เฉพาะ JSON เท่านั้นที่รองรับเป็นรูปแบบการตอบกลับใน
การค้นหาใกล้เคียง (ใหม่)
- ตอนนี้คำขอทั้งหมดที่มีการค้นหาข้อความควรใช้
การค้นหาข้อความ (ใหม่)
เนื่องจากการค้นหาใกล้เคียง (ใหม่) ไม่รองรับการป้อนข้อความ
- รูปแบบการตอบกลับ JSON สำหรับการค้นหาใกล้เคียง (ใหม่)
มีการเปลี่ยนแปลงจากรูปแบบของ API เดิม ดูรายละเอียดเพิ่มเติมได้ที่
ย้ายข้อมูลการตอบกลับของ Places API
ตารางต่อไปนี้แสดงพารามิเตอร์ในการค้นหาใกล้เคียง (เดิม) ที่มีการ
เปลี่ยนชื่อหรือแก้ไขสำหรับการค้นหาใกล้เคียง (ใหม่) หรือพารามิเตอร์ที่
ไม่รองรับอีกต่อไป
พารามิเตอร์ปัจจุบัน |
พารามิเตอร์ใหม่ |
หมายเหตุ |
keyword |
|
ไม่รองรับ โปรดใช้
การค้นหาข้อความ (ใหม่)
แทน |
language |
languageCode |
|
location |
locationRestriction |
ต้องระบุ |
maxprice/minprice |
|
ไม่รองรับ |
|
maxResultCount |
พารามิเตอร์ใหม่ |
opennow |
|
ไม่รองรับ |
pagetoken |
|
ไม่รองรับ |
radius |
|
ใช้ locationRestriction เลย |
rankby |
rankPreference |
|
|
regionCode |
พารามิเตอร์ใหม่ |
type |
includedTypes
excludedTypes
includedPrimaryTypes
excludedPrimaryTypes
|
นอกจากนี้ พารามิเตอร์ใหม่ยังยอมรับค่าประเภทหลายค่าด้วย API เดิม
ยอมรับค่าเดียวเท่านั้น |
ตัวอย่างคำขอ
คำขอ GET ตัวอย่างต่อไปนี้ใช้การค้นหาใกล้เคียง (เดิม) ในตัวอย่างนี้ คุณขอการตอบกลับ JSON ที่มีข้อมูลเกี่ยวกับสถานที่ประเภท
restaurant
และส่งพารามิเตอร์ทั้งหมดเป็นพารามิเตอร์ URL
curl -L -X GET \
'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.7937%2C-122.3965&radius=500&type=restaurant&key=API_KEY'
เมื่อใช้การค้นหาใกล้เคียง (ใหม่) คุณจะส่งคำขอ POST และส่งพารามิเตอร์ทั้งหมด
ในเนื้อความของคำขอ JSON หรือในส่วนหัวเป็นส่วนหนึ่งของคำขอ POST
ตัวอย่างนี้ยังใช้มาสก์ฟิลด์เพื่อให้การตอบกลับมีเฉพาะชื่อที่แสดงและที่อยู่ที่จัดรูปแบบของสถานที่
curl -X POST -d '{
"includedTypes": ["restaurant"],
"locationRestriction": {
"circle": {
"center": {
"latitude": 37.7937,
"longitude": -122.3965},
"radius": 500.0
}
}
}' \
-H 'Content-Type: application/json' -H "X-Goog-Api-Key: API_KEY" \
-H "X-Goog-FieldMask: places.displayName,places.formattedAddress" \
https://places.googleapis.com/v1/places:searchNearby
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[],[],null,["# Migrate to Nearby Search (New)\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\nIntroduction\n------------\n\nPlaces API supports\n[Nearby Search (Legacy)](/maps/documentation/places/web-service/search-nearby).\nIf you are familiar with Nearby Search (Legacy), the [Nearby Search (New)](/maps/documentation/places/web-service/nearby-search) makes the following\nchanges:\n\n- Nearby Search (New) uses HTTP POST requests. Pass parameters in the request body or in headers as part of an HTTP POST request. In contrast, with Nearby Search (Legacy), you pass URL parameters using an HTTP GET request.\n- Field masking is required. You must specify which fields you want returned in the response. There is no default list of returned fields. If you omit this list, the methods return an error. For more information, see [FieldMask](/maps/documentation/places/web-service/nearby-search#fieldmask).\n- Nearby Search (New) supports both [API keys](/maps/documentation/places/web-service/get-api-key) and [OAuth](/maps/documentation/places/web-service/oauth-token) tokens as the authentication mechanism.\n- Only JSON is supported as a response format in Nearby Search (New).\n- All requests that include a text query should now use [Text Search (New)](/maps/documentation/places/web-service/text-search) because Nearby Search (New) does not support text input.\n- The JSON response format for Nearby Search (New) has changed from the format of the legacy APIs. For more details, see [Migrate the Places API response](/maps/documentation/places/web-service/migrate-response).\n\nThe following table lists parameters in Nearby Search (Legacy) that have been\nrenamed or modified for Nearby Search (New), or parameters that are no\nlonger supported.\n\n| Current parameter | New parameter | Notes |\n|---------------------|-------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|\n| `keyword` | | Not supported. Use [Text Search (New)](/maps/documentation/places/web-service/text-search) instead. |\n| `language` | `languageCode` | |\n| `location` | `locationRestriction` | Required. |\n| `maxprice/minprice` | | Not supported. |\n| | `maxResultCount` | New parameter. |\n| `opennow` | | Not supported. |\n| `pagetoken` | | Not supported. |\n| `radius` | | Use `locationRestriction` now. |\n| `rankby` | `rankPreference` | |\n| | `regionCode` | New parameter. |\n| `type` | `includedTypes` `excludedTypes` `includedPrimaryTypes` `excludedPrimaryTypes` | The new parameters also accept multiple type values. The legacy API only accepts a single value. |\n\nExample request\n---------------\n\nThe following example GET request uses the Nearby Search (Legacy). In this\nexample, you request a JSON response containing information about places of type\n`restaurant` and pass all parameters as URL parameters: \n\n```curl\ncurl -L -X GET \\\n'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.7937%2C-122.3965&radius=500&type=restaurant&key=API_KEY'\n```\n\nWith Nearby Search (New), you make a POST request and pass all\nparameters in the JSON request body or in headers as part of the POST request.\nThis example also uses a field mask so the response only includes the display\nname and formatted address of the place: \n\n```curl\ncurl -X POST -d '{\n \"includedTypes\": [\"restaurant\"],\n \"locationRestriction\": {\n \"circle\": {\n \"center\": {\n \"latitude\": 37.7937,\n \"longitude\": -122.3965},\n \"radius\": 500.0\n }\n }\n}' \\\n-H 'Content-Type: application/json' -H \"X-Goog-Api-Key: API_KEY\" \\\n-H \"X-Goog-FieldMask: places.displayName,places.formattedAddress\" \\\nhttps://places.googleapis.com/v1/places:searchNearby\n```"]]