คอมโพเนนต์การค้นหาสถานที่ขั้นสูง

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

การกำหนดค่าการค้นหาสถานที่ขั้นสูง

ใช้ AdvancedPlaceSearchFragment เพื่อเข้าถึงฟีเจอร์ขั้นสูง

กำหนดค่าปุ่มการดำเนินการ

ใช้อินเทอร์เฟซ PlaceActionProvider ของ AdvancedPlaceSearchFragment เพื่อกำหนดและปรับแต่งปุ่มการดำเนินการ

ข้อกำหนดการระบุแหล่งที่มาด้วยภาพ

มุมมองการค้นหาสถานที่ขั้นสูงพร้อมปุ่มที่ปรับแต่งแล้ว
ผลการค้นหาสถานที่พร้อมปุ่มที่กำหนดเอง

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

ตัวอย่างแสดงรูปภาพที่กำหนดเองซึ่งระบุอย่างชัดเจนว่าจะมีการส่งข้อมูลผู้ใช้ไปยัง "Altostrat"

ใช้ตัวเลือกการค้นหาและการกรอง

ใช้อินเทอร์เฟซ SearchMediaOptions และ SearchReviewsOptions ของ AdvancedPlaceSearchFragment เพื่อเปิดใช้การค้นหาและการกรองสื่อหรือรีวิว

ตัวอย่างการค้นหาสถานที่ขั้นสูง

สร้างส่วนย่อย AdvancedPlaceSearch

Kotlin

// Initialize Places first
Places.initializeWithNewPlacesApiEnabled(context, API_KEY)

// How the fragment is created
AdvancedPlaceSearchFragment.newInstance(
          selectedContent,
          orientation,
          R.style.BrandedPlaceDetailsTheme,
        )

// Fragment supports the same configs that PlaceSearchFragment supported
fragment.preferTruncation = false
fragment.attributionPosition = AttributionPosition.BOTTOM
fragment.selectable = true

        

Kotlin

// Performing a search works the same as with a regular placeSearchFragment.

advancedPlaceSearchFragment.configureFromSearchByTextRequest(searchByTextRequest)

advancedPlaceSearchFragment.configureFromSearchNearbyRequest(searchNearbyRequest)


        

ฟังผลการค้นหา

Kotlin

// attach the existing PlaceSearchFragmentListener to get notified about when places load or are selected from the results list.  
override fun onAttachFragment(fragment: Fragment) {
    super.onAttachFragment(fragment)
    when (fragment) {
      // Reuse the placeSearchFragmetnListener from the Essentials version
      is AdvancedPlaceSearchFragment -> fragment.registerListener(placeSearchFragmentListener)
      // use placeListFragmentListener, its functionally identical but with a new name.  
      is AdvancedPlaceListFragment -> fragment.registerListener(advancedPlaceListFragmentListener)
    }
}