การค้นหาในบริเวณใกล้เคียง (ใหม่)

เลือกแพลตฟอร์ม: Android iOS JavaScript เว็บเซอร์วิส
นักพัฒนาซอฟต์แวร์ในเขตเศรษฐกิจยุโรป (EEA)

บทนำ

คำขอการค้นหาในบริเวณใกล้เคียง (ใหม่) จะใช้ประเภทสถานที่อย่างน้อย 1 ประเภท และแสดงผลรายการสถานที่ที่ตรงกันภายในพื้นที่ที่ ระบุ คุณต้องระบุ FieldMask ที่ระบุประเภทข้อมูลอย่างน้อย 1 ประเภท การค้นหาในบริเวณใกล้เคียง (ใหม่) รองรับเฉพาะคำขอ POST

โปรแกรมสำรวจ APIs ช่วยให้คุณส่งคำขอแบบสดได้ เพื่อให้คุณคุ้นเคยกับ API และตัวเลือก API

ลองใช้เดโม แบบอินเทอร์แอกทีฟเพื่อดูผลการค้นหาในบริเวณใกล้เคียง (ใหม่) ที่แสดงบนแผนที่

คำขอการค้นหาในบริเวณใกล้เคียง (ใหม่)

คำขอการค้นหาในบริเวณใกล้เคียง (ใหม่) คือคำขอ HTTP POST ไปยัง URL ในรูปแบบต่อไปนี้

https://places.googleapis.com/v1/places:searchNearby

ส่งพารามิเตอร์ทั้งหมดในเนื้อหาคำขอ JSON หรือในส่วนหัวโดยเป็นส่วนหนึ่งของคำขอ POST เช่น

curl -X POST -d '{
  "includedTypes": ["restaurant"],
  "maxResultCount": 10,
  "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" \
https://places.googleapis.com/v1/places:searchNearby

การตอบกลับการค้นหาในบริเวณใกล้เคียง (ใหม่)

การค้นหาในบริเวณใกล้เคียง (ใหม่) จะแสดงผล ออบเจ็กต์ JSON เป็นการตอบกลับ โดยการตอบกลับจะมีข้อมูลดังนี้

  • อาร์เรย์ places มีสถานที่ที่ตรงกันทั้งหมด
  • สถานที่แต่ละแห่งในอาร์เรย์จะแสดงด้วย Place ออบเจ็กต์ ออบเจ็กต์ Place มีข้อมูลโดยละเอียดเกี่ยวกับสถานที่แห่งเดียว
  • FieldMask ที่ส่งในคำขอจะระบุรายการฟิลด์ ที่แสดงในออบเจ็กต์ Place

ออบเจ็กต์ JSON ที่สมบูรณ์จะอยู่ในรูปแบบดังนี้

{
  "places": [
    {
      object (Place)
    }
  ]
}

พารามิเตอร์ที่จำเป็น

  • FieldMask

    ระบุรายการฟิลด์ที่จะแสดงในการตอบกลับโดยสร้าง FieldMask ของการตอบกลับ ส่ง FieldMask ของการตอบกลับไปยังเมธอดโดยใช้พารามิเตอร์ URL $fields หรือ fields หรือโดยใช้ส่วนหัว HTTP X-Goog-FieldMask ไม่มีรายการฟิลด์เริ่มต้นที่แสดงในการตอบกลับ หากคุณละเว้น FieldMask เมธอดจะแสดงข้อผิดพลาด

    การมาสก์ฟิลด์เป็นแนวทางปฏิบัติที่ดีในการออกแบบเพื่อให้มั่นใจว่าคุณจะไม่ขอ ข้อมูลที่ไม่จำเป็น ซึ่งจะช่วยหลีกเลี่ยงเวลาในการประมวลผลและ ค่าใช้จ่ายในการเรียกเก็บเงินที่ไม่จำเป็น

    ระบุรายการประเภทข้อมูลสถานที่ที่คั่นด้วยคอมมาที่จะแสดง เช่น หากต้องการดึงข้อมูลชื่อที่แสดงและที่อยู่ของสถานที่

    X-Goog-FieldMask: places.displayName,places.formattedAddress

    ใช้ * เพื่อดึงข้อมูลฟิลด์ทั้งหมด

    X-Goog-FieldMask: *

    ระบุฟิลด์ต่อไปนี้อย่างน้อย 1 รายการ

    • ฟิลด์ต่อไปนี้จะเรียกใช้ SKU การค้นหาในบริเวณใกล้เคียงแบบ Pro:

      places.accessibilityOptions
      places.addressComponents
      places.addressDescriptor*
      places.adrFormatAddress
      places.attributions
      places.businessStatus
      places.containingPlaces
      places.displayName
      places.formattedAddress
      places.googleMapsLinks
      places.googleMapsUri
      places.iconBackgroundColor
      places.iconMaskBaseUri
      places.id
      places.location
      places.name**
      places.movedPlace
      places.movedPlaceId
      places.openingDate
      places.photos
      places.plusCode
      places.postalAddress
      places.primaryType
      places.primaryTypeDisplayName
      places.pureServiceAreaBusiness
      places.shortFormattedAddress
      places.subDestinations
      places.timeZone
      places.types
      places.utcOffsetMinutes
      places.viewport

      * ตัวอธิบายที่อยู่พร้อมให้บริการแก่ลูกค้าในอินเดียโดยทั่วไป และเป็นเวอร์ชันทดลองในประเทศอื่นๆ

      ** ฟิลด์ places.name มี ชื่อทรัพยากร ของสถานที่ในรูปแบบ places/PLACE_ID ใช้ places.displayName เพื่อเข้าถึงชื่อข้อความของสถานที่

    • ฟิลด์ต่อไปนี้จะเรียกใช้ SKU การค้นหาในบริเวณใกล้เคียงแบบ Enterprise:

      places.currentOpeningHours
      places.currentSecondaryOpeningHours
      places.internationalPhoneNumber
      places.nationalPhoneNumber
      places.priceLevel
      places.priceRange
      places.rating
      places.regularOpeningHours
      places.regularSecondaryOpeningHours
      places.transitStation
      places.userRatingCount
      places.websiteUri

    • ฟิลด์ต่อไปนี้จะเรียกใช้ SKU การค้นหาในบริเวณใกล้เคียงแบบ Enterprise + บรรยากาศ:

      places.allowsDogs
      places.curbsidePickup
      places.delivery
      places.dineIn
      places.editorialSummary
      places.evChargeAmenitySummary
      places.evChargeOptions
      places.fuelOptions
      places.generativeSummary
      places.goodForChildren
      places.goodForGroups
      places.goodForWatchingSports
      places.liveMusic
      places.menuForChildren
      places.neighborhoodSummary
      places.parkingOptions
      places.paymentOptions
      places.outdoorSeating
      places.reservable
      places.restroom
      places.reviews
      places.reviewSummary
      routingSummaries*
      places.servesBeer
      places.servesBreakfast
      places.servesBrunch
      places.servesCocktails
      places.servesCoffee
      places.servesDessert
      places.servesDinner
      places.servesLunch
      places.servesVegetarianFood
      places.servesWine
      places.takeout

      * การค้นหาข้อความและการค้นหาในบริเวณใกล้เคียงเท่านั้น

  • locationRestriction

    ภูมิภาคที่จะค้นหาที่ระบุเป็นวงกลม ซึ่งกำหนดโดยจุดศูนย์กลางและรัศมีเป็นเมตร รัศมีต้องอยู่ระหว่าง 0.0 ถึง 50000.0 เท่านั้น รัศมีเริ่มต้นคือ 0.0 คุณต้อง ตั้งค่าในคำขอเป็นค่าที่มากกว่า 0.0

    เช่น

    "locationRestriction": {
      "circle": {
        "center": {
          "latitude": 37.7937,
          "longitude": -122.3965
        },
        "radius": 500.0
      }
    }

พารามิเตอร์ที่ไม่บังคับ

  • includeFutureOpeningBusinesses

    หากเป็น true ระบบจะแสดงธุรกิจที่คาดว่าจะเปิดในอนาคต ค่าเริ่มต้นคือ false

    หากต้องการดึงข้อมูลสถานะธุรกิจ ให้ใส่ places.businessStatusใน FieldMask ของคำขอ หากต้องการดึงข้อมูลวันที่คาดว่าจะเปิดทำการของธุรกิจ ให้ใส่ places.openingDate ใน FieldMask ของคำขอ

  • includedTypes/excludedTypes, includedPrimaryTypes/excludedPrimaryTypes

    ช่วยให้คุณระบุรายการประเภทจากประเภท ตาราง A ที่ใช้กรอง ผลการค้นหาได้ คุณระบุประเภทได้สูงสุด 50 ประเภทในหมวดหมู่ข้อจำกัดประเภทแต่ละหมวดหมู่

    สถานที่หนึ่งๆ จะมีประเภทหลักเพียงประเภทเดียว จากตาราง A ของประเภทที่เชื่อมโยงกับสถานที่นั้น เช่น ประเภทหลักอาจเป็น "mexican_restaurant" หรือ "steak_house" ใช้ includedPrimaryTypes และ excludedPrimaryTypes เพื่อกรองผลลัพธ์ตาม ประเภทหลักของสถานที่

    นอกจากนี้ สถานที่หนึ่งๆ ยังมีค่าประเภทหลายค่า จากประเภท ตาราง A ที่เชื่อมโยงกับสถานที่นั้นได้ด้วย เช่น ร้านอาหารอาจมีประเภทต่อไปนี้ "seafood_restaurant", "restaurant", "food", "point_of_interest", "establishment" ใช้ includedTypes และ excludedTypes เพื่อกรองผลลัพธ์ตามรายการประเภทที่เชื่อมโยงกับ สถานที่

    เมื่อคุณระบุประเภทหลักทั่วไป เช่น "restaurant" หรือ "hotel" การตอบกลับอาจมีสถานที่ที่มีประเภทหลักที่เฉพาะเจาะจงกว่า ประเภทที่ระบุ เช่น คุณระบุให้รวมประเภทหลัก "restaurant". การตอบกลับอาจมีสถานที่ที่มีประเภทหลัก "restaurant" แต่การตอบกลับอาจมีสถานที่ที่มีประเภทหลักที่เฉพาะเจาะจงกว่า เช่น "chinese_restaurant" หรือ "seafood_restaurant"

    หากมีการระบุการค้นหาที่มีข้อจำกัดประเภทหลายรายการ ระบบจะแสดงเฉพาะสถานที่ ที่ตรงตามข้อจำกัดทั้งหมด เช่น หากคุณระบุ {"includedTypes": ["restaurant"], "excludedPrimaryTypes": ["steak_house"]} สถานที่ที่แสดงจะให้บริการที่เกี่ยวข้องกับ "restaurant" แต่ไม่ได้ดำเนินการเป็น "steak_house" เป็นหลัก

    includedTypes

    รายการประเภทสถานที่จาก ตาราง A ที่คั่นด้วยคอมมาที่จะค้นหา หากละเว้นพารามิเตอร์นี้ ระบบจะแสดงสถานที่ทุกประเภท

    excludedTypes

    รายการประเภทสถานที่จาก ตาราง A ที่คั่นด้วยคอมมาที่จะยกเว้นจากการค้นหา

    หากคุณระบุทั้ง includedTypes ( เช่น "school") และ excludedTypes (เช่น "primary_school") ในคำขอ การตอบกลับจะมีสถานที่ที่จัดอยู่ในหมวดหมู่ "school" แต่ไม่ใช่ "primary_school" การตอบกลับจะมีสถานที่ที่ตรงกับ อย่างน้อย 1 รายการ ของ includedTypes และ ไม่มี excludedTypes

    หากมีประเภทที่ขัดแย้งกัน เช่น ประเภทที่ปรากฏทั้งใน includedTypes และ excludedTypes ระบบจะแสดงข้อผิดพลาด INVALID_REQUEST

    includedPrimaryTypes

    รายการประเภทสถานที่หลักจาก ตาราง A ที่คั่นด้วยคอมมาที่จะรวมในการค้นหา

    excludedPrimaryTypes

    รายการประเภทสถานที่หลักจาก ตาราง A ที่คั่นด้วยคอมมาที่จะยกเว้น จากการค้นหา

    หากมีประเภทหลักที่ขัดแย้งกัน เช่น ประเภทที่ปรากฏทั้งใน includedPrimaryTypes และ excludedPrimaryTypes ระบบจะแสดงข้อผิดพลาด INVALID_ARGUMENT

  • languageCode

    ภาษาที่จะแสดงผลลัพธ์

    • ดูรายการภาษาที่รองรับ Google มักจะ อัปเดตภาษาที่รองรับ ดังนั้นรายการนี้อาจไม่ครอบคลุมทั้งหมด
    • หากไม่ได้ระบุ languageCode API จะใช้ en เป็นค่าเริ่มต้น หากคุณระบุรหัสภาษาที่ไม่ถูกต้อง API จะแสดงข้อผิดพลาด INVALID_ARGUMENT
    • API จะพยายามอย่างเต็มที่เพื่อให้ที่อยู่ที่อ่านง่ายสำหรับทั้งผู้ใช้และ คนในพื้นที่ เพื่อให้บรรลุเป้าหมายดังกล่าว ระบบจะแสดงที่อยู่ในภาษาท้องถิ่น แปลงเป็นสคริปต์ที่ผู้ใช้อ่านได้หากจำเป็น ตามภาษาที่ต้องการ ส่วนที่อยู่อื่นๆ จะแสดงในภาษาที่ต้องการ คอมโพเนนต์ของที่อยู่ทั้งหมดจะแสดงในภาษาเดียวกัน ซึ่งเลือกจากคอมโพเนนต์แรก
    • หากชื่อไม่มีในภาษาที่ต้องการ API จะใช้ชื่อที่ใกล้เคียงที่สุด
    • ภาษาที่ต้องการมีอิทธิพลเล็กน้อยต่อชุดผลลัพธ์ที่ API เลือกที่จะแสดง และลำดับที่แสดง ตัวเข้ารหัสพิกัดภูมิศาสตร์จะตีความตัวย่อ แตกต่างกันไปตามภาษา เช่น ตัวย่อสำหรับประเภทถนน หรือคำพ้องความหมาย ที่อาจใช้ได้ในภาษาหนึ่งแต่ใช้ไม่ได้ในอีกภาษาหนึ่ง
  • maxResultCount

    ระบุจำนวนผลลัพธ์สถานที่สูงสุดที่จะแสดง ต้องอยู่ระหว่าง 1 ถึง 20 (ค่าเริ่มต้น) เท่านั้น

  • rankPreference

    ประเภทการจัดอันดับที่จะใช้ หากละเว้นพารามิเตอร์นี้ ระบบจะจัดอันดับผลลัพธ์ตามความนิยม ซึ่งอาจเป็นค่าใดค่าหนึ่งต่อไปนี้

    • POPULARITY (ค่าเริ่มต้น) จัดเรียงผลลัพธ์ตามความนิยม
    • DISTANCE จัดเรียงผลลัพธ์จากน้อยไปมากตามระยะทางจากสถานที่ที่ระบุ
  • regionCode

    รหัสภูมิภาคที่ใช้จัดรูปแบบการตอบกลับ ซึ่งระบุเป็นค่ารหัส CLDR 2 หลัก ไม่มีค่าเริ่มต้น

    หากชื่อประเทศของฟิลด์ formattedAddress ในการตอบกลับตรงกับ regionCode ระบบจะละเว้นรหัสประเทศจาก formattedAddress พารามิเตอร์นี้ไม่มีผลกับ adrFormatAddress ซึ่งจะมีชื่อประเทศ อยู่เสมอ หรือกับ shortFormattedAddress ซึ่งจะไม่มีชื่อประเทศ

    รหัส CLDR ส่วนใหญ่จะเหมือนกับ รหัส ISO 3166-1 ยกเว้นบางรายการ เช่น ccTLD ของสหราชอาณาจักรคือ "uk" (.co.uk) ขณะที่รหัส ISO 3166-1 คือ "gb" (ในทางเทคนิคสำหรับ หน่วยงาน "สหราชอาณาจักรบริเตนใหญ่และไอร์แลนด์เหนือ") พารามิเตอร์นี้อาจส่งผลต่อผลลัพธ์ตามกฎหมายที่เกี่ยวข้อง

ตัวอย่างการค้นหาในบริเวณใกล้เคียง (ใหม่)

ค้นหาสถานที่ประเภทเดียว

ตัวอย่างต่อไปนี้แสดงคำขอการค้นหาในบริเวณใกล้เคียง (ใหม่) สำหรับชื่อที่แสดงของร้านอาหารทั้งหมดภายในรัศมี 500 เมตร ซึ่งกำหนดโดย circle

curl -X POST -d '{
  "includedTypes": ["restaurant"],
  "maxResultCount": 10,
  "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" \
https://places.googleapis.com/v1/places:searchNearby

โปรดทราบว่าส่วนหัว X-Goog-FieldMask ระบุว่าการตอบกลับมีฟิลด์ข้อมูลต่อไปนี้ places.displayName การตอบกลับจึงอยู่ในรูปแบบต่อไปนี้

{
  "places": [
    {
      "displayName": {
        "text": "La Mar Cocina Peruana",
        "languageCode": "en"
      }
    },
    {
      "displayName": {
        "text": "Kokkari Estiatorio",
        "languageCode": "en"
      }
    },
    {
      "displayName": {
        "text": "Harborview Restaurant & Bar",
        "languageCode": "en"
      }
    },
...
}

เพิ่มประเภทข้อมูลลงใน FieldMask เพื่อแสดงข้อมูลเพิ่มเติม เช่น เพิ่ม places.formattedAddress,places.types,places.websiteUri เพื่อรวมที่อยู่ ประเภท และที่อยู่เว็บของร้านอาหารในการตอบกลับ

curl -X POST -d '{
  "includedTypes": ["restaurant"],
  "maxResultCount": 10,
  "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,places.types,places.websiteUri" \
https://places.googleapis.com/v1/places:searchNearby

ตอนนี้การตอบกลับอยู่ในรูปแบบต่อไปนี้

{
  "places": [
    {
      "types": [
        "seafood_restaurant",
        "restaurant",
        "food",
        "point_of_interest",
        "establishment"
      ],
      "formattedAddress": "PIER 1 1/2 The Embarcadero N, San Francisco, CA 94105, USA",
      "websiteUri": "http://lamarsf.com/",
      "displayName": {
        "text": "La Mar Cocina Peruana",
        "languageCode": "en"
      }
    },
    {
      "types": [
        "greek_restaurant",
        "meal_takeaway",
        "restaurant",
        "food",
        "point_of_interest",
        "establishment"
      ],
      "formattedAddress": "200 Jackson St, San Francisco, CA 94111, USA",
      "websiteUri": "https://kokkari.com/",
      "displayName": {
        "text": "Kokkari Estiatorio",
        "languageCode": "en"
      }
    },
...
}

ค้นหาสถานที่หลายประเภท

ตัวอย่างต่อไปนี้แสดงคำขอการค้นหาในบริเวณใกล้เคียง (ใหม่) สำหรับชื่อที่แสดงของร้านสะดวกซื้อและร้านขายสุราทั้งหมดภายในรัศมี 1,000 เมตรจาก circle ที่ระบุ

curl -X POST -d '{
  "includedTypes": ["liquor_store", "convenience_store"],
  "maxResultCount": 10,
  "locationRestriction": {
    "circle": {
      "center": {
        "latitude": 37.7937,
        "longitude": -122.3965
      },
      "radius": 1000.0
    }
  }
}' \
-H 'Content-Type: application/json' -H "X-Goog-Api-Key: API_KEY" \
-H "X-Goog-FieldMask: places.displayName,places.primaryType,places.types" \
https://places.googleapis.com/v1/places:searchNearby
ตัวอย่างนี้เพิ่ม places.primaryType และ places.types ลงใน FieldMask เพื่อให้การตอบกลับมีข้อมูลประเภทเกี่ยวกับสถานที่แต่ละแห่ง ซึ่งจะช่วยให้เลือกสถานที่ที่เหมาะสมจากผลลัพธ์ได้ง่ายขึ้น

ตัวอย่างต่อไปนี้แสดงคำขอการค้นหาในบริเวณใกล้เคียง (ใหม่) สำหรับสถานที่ทุกแห่งประเภท "school" โดยยกเว้นสถานที่ทุกแห่งประเภท "primary_school" และจัดอันดับผลลัพธ์ตามระยะทาง

curl -X POST -d '{
  "includedTypes": ["school"],
  "excludedTypes": ["primary_school"],
  "maxResultCount": 10,
  "locationRestriction": {
    "circle": {
      "center": {
        "latitude": 37.7937,
        "longitude": -122.3965
      },
      "radius": 1000.0
    }
  },
  "rankPreference": "DISTANCE"
}' \
-H 'Content-Type: application/json' -H "X-Goog-Api-Key: API_KEY" \
-H "X-Goog-FieldMask: places.displayName" \
https://places.googleapis.com/v1/places:searchNearby

ค้นหาสถานที่ทั้งหมดที่อยู่ใกล้พื้นที่หนึ่งๆ โดยจัดอันดับตามระยะทาง

ตัวอย่างต่อไปนี้แสดงคำขอการค้นหาในบริเวณใกล้เคียง (ใหม่) สำหรับสถานที่ที่อยู่ใกล้จุดหนึ่งในใจกลางเมืองซานฟรานซิสโก ในตัวอย่างนี้ คุณจะใส่พารามิเตอร์ rankPreference เพื่อจัดอันดับผลลัพธ์ตามระยะทาง

curl -X POST -d '{
  "maxResultCount": 10,
  "rankPreference": "DISTANCE",
  "locationRestriction": {
    "circle": {
      "center": {
        "latitude": 37.7937,
        "longitude": -122.3965
      },
      "radius": 1000.0
    }
  }
}' \
-H 'Content-Type: application/json' -H "X-Goog-Api-Key: API_KEY" \
-H "X-Goog-FieldMask: places.displayName" \
https://places.googleapis.com/v1/places:searchNearby

รับตัวอธิบายที่อยู่

ตัวอธิบายที่อยู่ให้ข้อมูลเชิงสัมพันธ์เกี่ยวกับสถานที่ตั้งของสถานที่ ซึ่งรวมถึงจุดสังเกตที่อยู่ใกล้เคียง และพื้นที่ที่สถานที่นั้นตั้งอยู่

ตัวอย่างต่อไปนี้แสดงคำขอการค้นหาในบริเวณใกล้เคียง (ใหม่) สำหรับสถานที่ที่อยู่ใกล้ ห้างสรรพสินค้าในซานโฮเซ ในตัวอย่างนี้ คุณจะใส่ addressDescriptors ใน FieldMask

curl -X POST -d '{
  "maxResultCount": 5,
  "locationRestriction": {
    "circle": {
      "center": {
        "latitude": 37.321328,
        "longitude": -121.946275
      },"radius": 1000
    }
  },
  "includedTypes": ["restaurant", "cafe"],
  "excludedTypes": [],
  "rankPreference":"POPULARITY"
}' \
-H 'Content-Type: application/json' \
-H "X-Goog-Api-Key: API_KEY" \
-H "X-Goog-FieldMask: places.displayName,places.addressDescriptor" \
https://places.googleapis.com/v1/places:searchNearby

การตอบกลับจะมีสถานที่ที่ระบุในคำขอ รายการสถานที่สำคัญที่อยู่ใกล้เคียงและระยะทางจากสถานที่นั้น รวมถึงรายการพื้นที่และความสัมพันธ์ในการตั้งอยู่ของสถานที่นั้น

  {
    "places": [
      {
        "displayName": {
          "text": "Westfield Valley Fair",
          "languageCode": "en"
        },
        "addressDescriptor": {
          "landmarks": [
            {
              "name": "places/ChIJ62_oCR7Lj4AR_MGWkSPotD4",
              "placeId": "ChIJ62_oCR7Lj4AR_MGWkSPotD4",
              "displayName": {
                "text": "Nordstrom",
                "languageCode": "en"
              },
              "types": [
                "clothing_store",
                "department_store",
                "establishment",
                "point_of_interest",
                "shoe_store",
                "store"
              ],
              "straightLineDistanceMeters": 114.76984,
              "travelDistanceMeters": 114.261856
            },
            {
              "name": "places/ChIJgexMlR_Lj4ARiKCKuhNnjn0",
              "placeId": "ChIJgexMlR_Lj4ARiKCKuhNnjn0",
              "displayName": {
                "text": "Valley Fair Mall Eyexam of CA",
                "languageCode": "en"
              },
              "types": [
                "establishment",
                "health",
                "point_of_interest"
              ],
              "straightLineDistanceMeters": 131.62566,
              "travelDistanceMeters": 237.33253
            },
            {
              "name": "places/ChIJWWIlNx7Lj4ARpe1E0ob-_GI",
              "placeId": "ChIJWWIlNx7Lj4ARpe1E0ob-_GI",
              "displayName": {
                "text": "Din Tai Fung",
                "languageCode": "en"
              },
              "types": [
                "establishment",
                "food",
                "point_of_interest",
                "restaurant"
              ],
              "straightLineDistanceMeters": 110.0775,
              "travelDistanceMeters": 171.41951
            },
            {
              "name": "places/ChIJwyfPQx7Lj4AR7bYI2A2Yc54",
              "placeId": "ChIJwyfPQx7Lj4AR7bYI2A2Yc54",
              "displayName": {
                "text": "Abercrombie & Fitch",
                "languageCode": "en"
              },
              "types": [
                "clothing_store",
                "establishment",
                "point_of_interest",
                "shoe_store",
                "store"
              ],
              "spatialRelationship": "DOWN_THE_ROAD",
              "straightLineDistanceMeters": 53.620117,
              "travelDistanceMeters": 2.4578214
            },
            {
              "name": "places/ChIJpycNQx7Lj4ARjhXw3PrM_kU",
              "placeId": "ChIJpycNQx7Lj4ARjhXw3PrM_kU",
              "displayName": {
                "text": "Hollister Co.",
                "languageCode": "en"
              },
              "types": [
                "clothing_store",
                "establishment",
                "point_of_interest",
                "shoe_store",
                "store"
              ],
              "spatialRelationship": "DOWN_THE_ROAD",
              "straightLineDistanceMeters": 56.53726,
              "travelDistanceMeters": 15.418246
            }
          ],
          "areas": [
            {
              "name": "places/ChIJb3F-EB7Lj4ARnHApQ_Hu1gI",
              "placeId": "ChIJb3F-EB7Lj4ARnHApQ_Hu1gI",
              "displayName": {
                "text": "Westfield Valley Fair",
                "languageCode": "en"
              },
              "containment": "WITHIN"
            },
            {
              "name": "places/ChIJXYuykB_Lj4AR1Ot8nU5q26Q",
              "placeId": "ChIJXYuykB_Lj4AR1Ot8nU5q26Q",
              "displayName": {
                "text": "Valley Fair",
                "languageCode": "en"
              },
              "containment": "WITHIN"
            },
            {
              "name": "places/ChIJtYoUX2DLj4ARKoKOb1G0CpM",
              "placeId": "ChIJtYoUX2DLj4ARKoKOb1G0CpM",
              "displayName": {
                "text": "Central San Jose",
                "languageCode": "en"
              },
              "containment": "OUTSKIRTS"
            }
          ]
        }
      },
  /.../
  }

ค้นหาธุรกิจที่จะเปิดในอนาคต

ตัวอย่างต่อไปนี้แสดงคำขอการค้นหาในบริเวณใกล้เคียง (ใหม่) สำหรับธุรกิจที่จะเปิดในอนาคตในนิวมีโดวส์ รัฐไอดาโฮ

curl -X POST \
-H "Content-Type: application/json" \
-H "X-Goog-Api-Key: API_KEY" \
-H "X-Goog-FieldMask: places.id,places.displayName,places.businessStatus,places.openingDate" \
-d '{
  "includeFutureOpeningBusinesses": true,
  "maxResultCount": 20,
  "locationRestriction": {
    "circle": {
      "center": {"latitude": 44.9755100, "longitude": -116.2842180},
      "radius": 20
    }
  },
  "rankPreference": "DISTANCE"
}' \
"https://places.googleapis.com/v1/places:searchNearby"

การตอบกลับจะมีธุรกิจที่จะเปิดในอนาคต รวมถึงสถานะธุรกิจ และวันที่คาดว่าจะเปิดทำการ

{
  "places": [
    {
      "id": "ChIJp1-VoKWJplQRMz8g-7Wa3Do",
      "businessStatus": "FUTURE_OPENING",
      "displayName": {
        "text": "Roberts Greenhouse and Tree Farm",
        "languageCode": "en"
      },
      "openingDate": {
        "year": 2026,
        "month": 4,
        "day": 15
      }
    }
  ]
}

รับข้อมูลสถานีขนส่ง

คุณสามารถใช้การค้นหาในบริเวณใกล้เคียง (ใหม่) เพื่อรับข้อมูลเกี่ยวกับสถานีขนส่งภายในรัศมีที่เจาะจงจากสถานที่ที่กำหนด เนื้อหาการตอบกลับจะมีข้อมูลเกี่ยวกับสถานี ซึ่งรวมถึงชื่อสถานี หน่วยงานขนส่งที่เกี่ยวข้อง และเส้นทางขนส่งที่ให้บริการสถานี นอกจากนี้ การตอบกลับยังมีไอคอนยานพาหนะและสีที่คุณใช้แสดงข้อมูลสถานีขนส่งได้

ตัวอย่างต่อไปนี้แสดงคำขอสำหรับสถานีขนส่งภายในรัศมี 50 เมตรจากมิดทาวน์แมนฮัตตัน

curl -X POST \
-H "Content-Type: application/json" \
-H "X-Goog-Api-Key: API_KEY" \
-H "X-Goog-FieldMask: places.id,places.displayName,places.transitStation" \
-d '{
  "includedTypes": ["transit_station"],
  "locationRestriction": {
    "circle": {
      "center": {"latitude": 40.754851, "longitude": -73.984164},
      "radius": 50.0
    }
  }
}' \
"https://places.googleapis.com/v1/places:searchNearby"

เนื้อหาการตอบกลับจะมีข้อมูลเกี่ยวกับสถานีแต่ละแห่งภายในรัศมี เส้นทางที่สถานีให้บริการ การแจ้งเตือนที่หน่วยงานขนส่งออก ณ ป้ายนั้น และข้อมูลการออกเดินทาง

{
  "places": [
    {
      "id": "ChIJH2EstKpZwokRCwZtYyMd5Fg",
      "displayName": {
        "text": "6 Av/W 41 St",
        "languageCode": "en"
      },
      "transitStation": {
        "displayName": {
          "text": "6 Av/W 41 St",
          "languageCode": "en"
        },
        "agencies": [
          {
            "displayName": {
              "text": "ShortLine Hudson",
              "languageCode": "en"
            },
            "url": "https://www.coachusa.com/",
            "lines": [
              {
                "id": "ChIJSQlbzvPwwokRolrIA-Kuh6o",
                "vehicleType": "BUS",
                "displayName": {
                  "text": "200 - Northern District – Nanuet",
                  "languageCode": "en"
                },
                "shortDisplayName": {
                  "text": "ShortLine Hudson",
                  "languageCode": "en"
                },
                "textColor": "#000000",
                "backgroundColor": "#ED60A3",
                "vehicleIcon": {
                  "url": "https://maps.gstatic.com/mapfiles/transit/iw2/svg/bus2.svg"
                }
              }
            ]
          },
          {
            "displayName": {
              "text": "MTA New York City Transit",
              "languageCode": "en"
            },
            "url": "http://www.mta.info/",
            "lines": [
              {
                "id": "ChIJjUrj7PBewokR3O3S2JVpBrI",
                "vehicleType": "SUBWAY",
                "displayName": {
                  "text": "E Train (8 Av Local)",
                  "languageCode": "en"
                },
                "shortDisplayName": {
                  "text": "E Line",
                  "languageCode": "en"
                },
                "textColor": "#FFFFFF",
                "backgroundColor": "#0039A6",
                "url": "https://www.mta.info/schedules/subway/e-train",
                "icon": {
                  "url": "https://maps.gstatic.com/mapfiles/transit/iw2/svg/us-ny-mta/E.svg",
                  "nameIncluded": true
                },
                "vehicleIcon": {
                  "url": "https://maps.gstatic.com/mapfiles/transit/iw2/svg/subway2.svg"
                }
              },
              ...
            ]
          },
        "stops": [
          {
            "id": "ChIJvRnquapZwokRdUOyVwNGbe8",
            "displayName": {
              "text": "6 Av/W 41 St",
              "languageCode": "en"
            },
            "location": {
              "latitude": 40.754509,
              "longitude": -73.984216500000016
            },
            "wheelchairAccessibleEntrance": true
          }
        ],
        "departureBoards": [
          {
            "displayType": "DIRECTION_CENTRIC",
            "rows": [
              {
                "departures": [
                  {
                    "timedDeparture": {
                      "scheduledTime": "2026-05-15T22:29:51Z",
                      "timingType": "SCHEDULED"
                    },
                    "originallyScheduledStopId": "ChIJvRnquapZwokRdUOyVwNGbe8",
                    "lineId": "ChIJA1aFyaZfwokRkO5869M6UXk"
                  }
                ]
              },
              {
                "departures": [
                  {
                    "timedDeparture": {
                      "scheduledTime": "2026-05-15T22:33:55Z",
                      "timingType": "SCHEDULED"
                    },
                    "originallyScheduledStopId": "ChIJvRnquapZwokRdUOyVwNGbe8",
                    "lineId": "ChIJj3iCEwJfwokRZE2Qtnm4pPI"
                  }
                ]
              },
              ...
            ]
          }
        ]
      }
    },
    ...
    {
      {
        "id": "ChIJPyq6TZBZwokRdGoiJ5Iq_hE",
        "vehicleType": "BUS",
        "displayName": {
          "text": "W 44 St - South Ferry",
          "languageCode": "en"
        },
        "shortDisplayName": {
          "text": "M55",
          "languageCode": "en"
        },
        "textColor": "#FFFFFF",
        "backgroundColor": "#1D59B3",
        "vehicleIcon": {
          "url": "https://maps.gstatic.com/mapfiles/transit/iw2/svg/bus2.svg"
        },
        "alerts": [
          {
            "effect": "OTHER",
            "texts": [
              {
                "headline": {
                  "text": "Information",
                  "languageCode": "en"
                },
                "summary": {
                  "text": "Northbound M20 and M55 stop on State St at Bridge St is closed; use the temporary stop on State St before the intersection instead",
                  "languageCode": "en"
                },
                "fullDescription": {
                  "text": "See a map of the new stop location. What's happening? Construction",
                  "languageCode": "en"
                }
              }
            ],
            "detailsUrls": [
              {
                "url": "https://www.mta.info/"
              }
            ],
            "cause": "OTHER_CAUSE",
            "startTime": "2025-04-02T04:00:00Z",
            "endTime": "2026-06-15T00:00:00Z",
            "attribution": {
              "link": {
                "text": "www.mta.info",
                "url": "https://www.mta.info/"
              }
            },
            "createTime": "2026-05-15T22:32:00Z",
            "severityLevel": "INFO"
          }
        ]
      },
      ...
    }
    ...
  }

ลองใช้งาน

โปรแกรมสำรวจ APIs ช่วยให้คุณส่งคำขอตัวอย่างได้ เพื่อให้คุณคุ้นเคยกับ API และตัวเลือก API

  1. เลือกไอคอน API api ทางด้านขวาของหน้า

  2. เลือกแก้ไขพารามิเตอร์คำขอ (ไม่บังคับ)

  3. เลือกปุ่มดำเนินการ ในกล่องโต้ตอบ ให้เลือกบัญชี ที่ต้องการใช้ส่งคำขอ

  4. ในแผงควบคุมโปรแกรมสำรวจ APIs ให้เลือกไอคอนเต็มหน้าจอ fullscreen เพื่อขยายหน้าต่างโปรแกรมสำรวจ APIs