স্থান বিবরণ উপাদান
প্লেস UI কিটের স্থানের বিবরণ উপাদান আপনাকে একটি পৃথক UI উপাদান যোগ করতে দেয় যা আপনার অ্যাপে স্থানের বিবরণ প্রদর্শন করে। এই উপাদানটি কাস্টমাইজযোগ্য।

স্থানের বিবরণ উপাদানটি স্বাধীনভাবে বা অন্যান্য Google মানচিত্র প্ল্যাটফর্ম API এবং পরিষেবাগুলির সাথে একত্রে ব্যবহার করা যেতে পারে। উপাদানটি হয় একটি স্থান আইডি , সম্পদের নাম বা অক্ষাংশ/দ্রাঘিমাংশ স্থানাঙ্ক নেয় এবং স্থানের বিবরণ তথ্য প্রদান করে।
স্থানের বিবরণ উপাদানটি সম্পূর্ণরূপে থিমযোগ্য, যা আপনাকে আপনার ব্যবহারের ক্ষেত্রে এবং ভিজ্যুয়াল ব্র্যান্ড নির্দেশিকাগুলির সাথে মেলে ফন্ট, রঙ এবং কর্নার রেডিআই কাস্টমাইজ করতে দেয়। আপনি একটি থিম তৈরি করে স্থানের বিবরণের চেহারা কাস্টমাইজ করতে পারেন যা PlacesMaterialTheme
প্রসারিত করে এবং থিম বৈশিষ্ট্যগুলির জন্য ওভাররাইড প্রদান করে। আপনি বিষয়বস্তু এন্ট্রিগুলির একটি তালিকা নির্দিষ্ট করে কোন স্থানের বিশদ ক্ষেত্রগুলি অন্তর্ভুক্ত করা হয়েছে তা কাস্টমাইজ করতে পারেন, যার প্রতিটি স্থান সম্পর্কে দেখানো তথ্যের একটি অংশের সাথে মিলে যায়।
লেআউট বৈকল্পিক
স্থানের বিবরণ উপাদান দুটি প্রধান বিন্যাস বৈকল্পিক সমর্থন করে:
- কমপ্যাক্ট: মূল তথ্যের পূর্বরূপ দেখার জন্য একটি বিন্যাস।
- সম্পূর্ণ: একটি বিস্তৃত লেআউট যা সমস্ত উপলব্ধ স্থানের বিবরণ প্রদর্শন করে।
কমপ্যাক্ট বিন্যাসটি উল্লম্ব বা অনুভূমিক অভিযোজনে প্রদর্শিত হতে পারে। এটি আপনাকে বিভিন্ন ডিজাইন লেআউট এবং স্ক্রীন আকারে উপাদানটিকে সংহত করতে দেয়। সম্পূর্ণ বিন্যাস শুধুমাত্র উল্লম্বভাবে প্রদর্শিত হতে পারে.

স্থানের বিবরণ উপাদান আপনাকে উপাদানটিতে প্রদর্শিত বিষয়বস্তুর উপর দানাদার নিয়ন্ত্রণ দেয়। প্রতিটি উপাদান (যেমন ফটো, পর্যালোচনা, এবং যোগাযোগের তথ্য) পৃথকভাবে দেখানো বা লুকানো যেতে পারে, উপাদানগুলির উপস্থিতি এবং তথ্য ঘনত্বের সুনির্দিষ্ট কাস্টমাইজেশনের জন্য অনুমতি দেয়।

স্থান বিবরণ কমপ্যাক্ট ভিউ
স্থানের বিবরণ কমপ্যাক্ট ফ্র্যাগমেন্ট ( PlaceDetailsCompactFragment
) ন্যূনতম স্থান ব্যবহার করে একটি নির্বাচিত স্থানের জন্য বিশদ রেন্ডার করে। এটি একটি তথ্য উইন্ডোতে একটি মানচিত্রে একটি স্থান হাইলাইট করে, একটি চ্যাটে একটি অবস্থান ভাগ করার মতো একটি সামাজিক মিডিয়া অভিজ্ঞতায়, আপনার বর্তমান অবস্থান নির্বাচন করার পরামর্শ হিসাবে বা Google মানচিত্রে স্থানটি উল্লেখ করার জন্য একটি মিডিয়া নিবন্ধের মধ্যে দরকারী হতে পারে৷
স্থান বিবরণ সম্পূর্ণ ভিউ
স্থানের বিশদ বিবরণ সম্পূর্ণ দর্শন ( PlaceDetailsFragment
) স্থানের বিশদ তথ্য প্রদর্শনের জন্য একটি বৃহত্তর পৃষ্ঠ অফার করে এবং আপনাকে আরও ধরনের তথ্য প্রদর্শন করতে দেয়।
বিষয়বস্তু প্রদর্শনের বিকল্প
আপনি PlaceDetailsCompactFragment.Content
বা PlaceDetailsFragment.Content
এ enums ব্যবহার করে কোন সামগ্রী প্রদর্শন করতে হবে তা নির্দিষ্ট করতে পারেন।
কমপ্যাক্ট ভিউ | সম্পূর্ণ ভিউ |
---|---|
|
|
বিলিং
স্থানের বিবরণ UI কিট ব্যবহার করার সময়, প্রতিবার .loadWithPlaceId()
, .loadWithResourceName()
বা loadWithCoordinates()
পদ্ধতিতে কল করার জন্য আপনাকে বিল করা হবে। আপনি একই জায়গা একাধিকবার লোড করলে, প্রতিটি অনুরোধের জন্য আপনাকে বিল দেওয়া হবে।
একাধিকবার চার্জ হওয়া এড়াতে, Android লাইফসাইকেল পদ্ধতিতে সরাসরি .loadWithPlaceId()
বা .loadWithResourceName()
যোগ করবেন না। উদাহরণস্বরূপ, onResume()
পদ্ধতিতে সরাসরি .loadWithPlaceId()
বা .loadWithResourceName()
কল করবেন না।
আপনার অ্যাপে জায়গার বিবরণ যোগ করুন
আপনি একটি লেআউটে একটি খণ্ড যোগ করে আপনার অ্যাপে স্থানের বিবরণ যোগ করতে পারেন। আপনি যখন খণ্ডটি ইনস্ট্যান্টিয়েট করেন, তখন আপনি আপনার প্রয়োজন অনুসারে এবং আপনার অ্যাপের চেহারার সাথে মেলে জায়গার বিশদ তথ্যের চেহারা এবং অনুভূতি কাস্টমাইজ করতে পারেন। কাস্টমাইজেশন সম্পর্কে আরও জানুন ।
কোটলিন এবং জাভা উভয় ক্ষেত্রেই আপনার কাছে তিনটি পদ্ধতি উপলব্ধ রয়েছে: একটি প্লেস আইডি ( loadWithPlaceId()
) দিয়ে টুকরো লোড করা, একটি রিসোর্স নাম ( loadWithResourceName()
) সহ খণ্ডটি লোড করা, এবং একটি অক্ষাংশ/দ্রাঘিমাংশ স্থানাঙ্ক ( loadWithCoordinates()
) সহ খণ্ডটি লোড করার জন্য। আপনি যেকোনো পদ্ধতি বা একাধিক বেছে নিতে পারেন।
কমপ্যাক্ট ভিউয়ের জন্য ডিফল্ট অবস্থান উল্লম্ব। আপনি যদি একটি অনুভূমিক বিন্যাস চান, তাহলে Orientation.HORIZONTAL
উল্লেখ করুন। আপনি স্বচ্ছতার জন্য ঐচ্ছিকভাবে Orientation.VERTICAL
উল্লেখ করতে পারেন। সম্পূর্ণ ভিউ শুধুমাত্র উল্লম্বভাবে প্রদর্শিত হতে পারে।
স্থান বিবরণ উপাদান উদাহরণ বিভাগে উদাহরণ দেখুন.
চাক্ষুষ চেহারা কাস্টমাইজ করুন

Places UI কিট মোটামুটিভাবে মেটেরিয়াল ডিজাইনের (কিছু Google-Maps-নির্দিষ্ট পরিবর্তন সহ) উপর ভিত্তি করে ভিজ্যুয়াল কাস্টমাইজেশনের জন্য একটি ডিজাইন সিস্টেম পদ্ধতির প্রস্তাব দেয়। রঙ এবং টাইপোগ্রাফির জন্য মেটেরিয়াল ডিজাইনের রেফারেন্স দেখুন। ডিফল্টরূপে, শৈলীটি Google মানচিত্রের ভিজ্যুয়াল ডিজাইনের ভাষা মেনে চলে।

একটি খণ্ডকে ইনস্ট্যান্টিয়েট করার সময়, আপনি একটি থিম নির্দিষ্ট করতে পারেন যা যেকোনো ডিফল্ট শৈলী বৈশিষ্ট্যকে ওভাররাইড করে। যে কোনো থিম বৈশিষ্ট্য ওভাররাইড করা হয় না ডিফল্ট শৈলী ব্যবহার করে। আপনি যদি একটি অন্ধকার থিম সমর্থন করতে চান, তাহলে আপনি values-night/colors.xml
এ রঙের জন্য একটি এন্ট্রি যোগ করতে পারেন।
<style name="CustomizedPlaceDetailsTheme" parent="PlacesMaterialTheme"> <item name="placesColorPrimary">@color/app_primary_color</item> <item name="placesColorOnSurface">@color/app_color_on_surface</item> <item name="placesColorOnSurfaceVariant">@color/app_color_on_surface</item> <item name="placesTextAppearanceBodySmall">@style/app_text_appearence_small</item> <item name="placesCornerRadius">20dp</item> </style>
আপনি নিম্নলিখিত শৈলী কাস্টমাইজ করতে পারেন:

থিম বৈশিষ্ট্য | ব্যবহার |
---|---|
রঙ | |
placesColorSurface | ধারক এবং ডায়ালগ ব্যাকগ্রাউন্ড |
placesColorOutlineDecorative | ধারক সীমানা |
placesColorPrimary | লিঙ্ক, লোডিং সূচক, ওভারভিউ আইকন |
placesColorOnSurface | শিরোনাম, সংলাপের বিষয়বস্তু |
placesColorOnSurfaceVariant | স্থান তথ্য |
placesColorSecondaryContainer | বোতাম ব্যাকগ্রাউন্ড |
placesColorOnSecondaryContainer | বোতাম পাঠ্য এবং আইকন |
placesColorNeutralContainer | তারিখ ব্যাজ পর্যালোচনা করুন, স্থানধারক আকার লোড হচ্ছে |
placesColorOnNeutralContainer | পর্যালোচনার তারিখ, লোডিং ত্রুটি৷ |
placesColorPositiveContainer | উপলব্ধ EV চার্জার ব্যাজ |
placesColorOnPositiveContainer | উপলব্ধ EV চার্জার ব্যাজ সামগ্রী |
placesColorPositive | "খুলুন" এখন লেবেল রাখুন |
placesColorNegative | "বন্ধ" এখন লেবেল রাখুন |
placesColorInfo | অ্যাক্সেসযোগ্য প্রবেশ আইকন |
placesColorButtonBorder | মানচিত্র এবং ঠিক আছে বোতাম খুলুন |
টাইপোগ্রাফি | |
placesTextAppearanceBodySmall | স্থান তথ্য |
placesTextAppearanceBodyMedium | স্থান তথ্য, ডায়ালগ বিষয়বস্তু |
placesTextAppearanceLabelMedium | ব্যাজ সামগ্রী |
placesTextAppearanceLabelLarge | বোতাম সামগ্রী |
placesTextAppearanceHeadlineMedium | ডায়ালগ শিরোনাম |
placesTextAppearanceDisplaySmall | স্থানের নাম |
placesTextAppearanceTitleSmall | স্থানের নাম |
ব্যবধান | |
placesSpacingExtraSmall | |
placesSpacingSmall | |
placesSpacingMedium | |
placesSpacingLarge | |
placesSpacingExtraLarge | |
placesSpacingTwoExtraLarge | |
পরিমাপ | |
placesBorderWidth | ধারক |
placesBorderWidthButton | |
আকৃতি | |
placesCornerRadius | ধারক |
placesCornerRadiusButton | মানচিত্র এবং ঠিক আছে বোতামে খুলুন (বৃত্তাকার আইকন বোতাম বাদ) |
placesCornerRadiusThumbnail | থাম্বনেইল ছবি রাখুন |
placesCornerRadiusCollageOuter | মিডিয়া কোলাজ |
placesCornerRadiusCard | প্লেস কার্ড, ইউজার রিভিউ কার্ড |
placesCornerRadiusDialog | Google Maps প্রকাশের ডায়ালগ |
গুগল ম্যাপ ব্র্যান্ড অ্যাট্রিবিউশন | |
placesColorAttributionLightTheme | হালকা থিম গুগল ম্যাপ অ্যাট্রিবিউশন এবং ডিসক্লোজার বোতাম (সাদা, ধূসর এবং কালো জন্য enums) |
placesColorAttributionDarkTheme | ডার্ক থিম গুগল ম্যাপ অ্যাট্রিবিউশন এবং ডিসক্লোজার বোতাম (সাদা, ধূসর এবং কালো জন্য enums) |
স্থান বিবরণ উপাদান উদাহরণ বিভাগে উদাহরণ দেখুন.
প্রস্থ এবং উচ্চতা কাস্টমাইজেশন
কমপ্যাক্ট ভিউ
প্রস্তাবিত প্রস্থ:
- উল্লম্ব অভিযোজন: 180dp এবং 300dp এর মধ্যে।
- অনুভূমিক অভিযোজন: 180dp এবং 500dp এর মধ্যে।
160dp এর চেয়ে ছোট প্রস্থ সঠিকভাবে প্রদর্শিত নাও হতে পারে।
সর্বোত্তম অনুশীলন হল কমপ্যাক্ট ভিউয়ের জন্য উচ্চতা নির্ধারণ না করা। এটি উইন্ডোতে থাকা বিষয়বস্তুকে উচ্চতা সেট করার অনুমতি দেবে, সমস্ত তথ্য প্রদর্শনের অনুমতি দেবে।
সম্পূর্ণ ভিউ
সম্পূর্ণ দর্শনের জন্য, প্রস্তাবিত প্রস্থ হল 250dp এবং 450dp-এর মধ্যে৷ 250dp এর চেয়ে ছোট একটি প্রস্থ সঠিকভাবে প্রদর্শন নাও করতে পারে।
আপনি উপাদানের উচ্চতা সেট করতে পারেন: উল্লম্ব স্থানের বিবরণ দৃশ্যটি বরাদ্দকৃত স্থানের মধ্যে উল্লম্বভাবে স্ক্রোল করবে।
সর্বোত্তম অনুশীলন হল সম্পূর্ণ দর্শনের জন্য একটি উচ্চতা সেট করা। এটি উইন্ডোতে থাকা বিষয়বস্তুকে সঠিকভাবে স্ক্রোল করার অনুমতি দেবে।
অ্যাট্রিবিউশন রং

Google Maps-এর পরিষেবার শর্তাবলীর জন্য আপনাকে Google Maps অ্যাট্রিবিউশনের জন্য তিনটি ব্র্যান্ডের রঙের একটি ব্যবহার করতে হবে। কাস্টমাইজেশন পরিবর্তন করা হলে এই অ্যাট্রিবিউশনটি দৃশ্যমান এবং অ্যাক্সেসযোগ্য হতে হবে।
আমরা বেছে নেওয়ার জন্য 3টি ব্র্যান্ডের রঙ অফার করি যা হালকা এবং অন্ধকার থিমের জন্য স্বাধীনভাবে সেট করা যেতে পারে:
- হালকা থিম: সাদা, ধূসর এবং কালোর জন্য enum মান সহ
placesColorAttributionLight
। - গাঢ় থিম: সাদা, ধূসর এবং কালোর জন্য enum মান সহ
placesColorAttributionDark
।
স্থান বিবরণ উপাদান উদাহরণ
একটি কমপ্যাক্ট বা সম্পূর্ণ ভিউ তৈরি করুন
কোটলিন
// We create a new instance of the fragment using its factory method. // We can specify which content to show, the orientation, and a custom theme. val fragment = PlaceDetailsCompactFragment.newInstance( PlaceDetailsCompactFragment.ALL_CONTENT, // Show all available content. orientation, R.style.CustomizedPlaceDetailsTheme, ).apply { // The PlaceLoadListener provides callbacks for when the place data is successfully // loaded or when an error occurs. This is where we update our UI state. setPlaceLoadListener(object : PlaceLoadListener { override fun onSuccess(place: Place) { Log.d(TAG, "Place loaded: ${place.id}") // Once the data is loaded, we hide the loading indicator and show the fragment. binding.loadingIndicatorMain.visibility = View.GONE binding.placeDetailsContainer.visibility = View.VISIBLE binding.dismissButton.visibility = View.VISIBLE } override fun onFailure(e: Exception) { Log.e(TAG, "Place failed to load", e) // On failure, we hide the UI and notify the user. dismissPlaceDetails() Toast.makeText(this@MainActivity, "Failed to load place details.", Toast.LENGTH_SHORT).show() } }) } // We add the fragment to our layout's container view. // `commitNow()` is used to ensure the fragment is immediately added and available, // which is important because we need to call a method on it right after. supportFragmentManager .beginTransaction() .replace(binding.placeDetailsContainer.id, fragment) .commitNow() // **This is the key step**: After adding the fragment, we call `loadWithPlaceId` // to trigger the data loading process for the selected place. // We use `post` to ensure this runs after the layout has been measured, // which can prevent potential timing issues. binding.root.post { fragment.loadWithPlaceId(placeId) } }
জাভা
PlaceDetailsCompactFragment fragment = PlaceDetailsCompactFragment.newInstance( Orientation.HORIZONTAL, Arrays.asList(Content.ADDRESS, Content.TYPE, Content.RATING, Content.ACCESSIBLE_ENTRANCE_ICON), R.style.CustomizedPlaceDetailsTheme); fragment.setPlaceLoadListener( new PlaceLoadListener() { @Override public void onSuccess(Place place) { ... } @Override public void onFailure(Exception e) { ... } }); getSupportFragmentManager() .beginTransaction() .add(R.id.fragment_container, fragment) .commitNow(); // Load the fragment with a Place ID. fragment.loadWithPlaceId(placeId); // Load the fragment with a resource name. fragment.loadWithResourceName(resourceName);
এই সম্পূর্ণ কোড নমুনা ব্যবহারকারীর ডিভাইসের কনফিগারেশনের উপর ভিত্তি করে প্রোগ্রাম্যাটিকভাবে কমপ্যাক্ট ভিউটির অভিযোজন নির্ধারণ করে।
কোটলিন
package com.example.placedetailsuikit import android.Manifest import android.annotation.SuppressLint import android.content.pm.PackageManager import android.content.res.Configuration import android.location.Location import android.os.Bundle import android.util.Log import android.view.View import android.widget.Toast import androidx.activity.enableEdgeToEdge import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.lifecycle.ViewModel import com.example.placedetailsuikit.databinding.ActivityMainBinding import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.OnMapReadyCallback import com.google.android.gms.maps.SupportMapFragment import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.PointOfInterest import com.google.android.libraries.places.api.Places import com.google.android.libraries.places.api.model.Place import com.google.android.libraries.places.widget.PlaceDetailsCompactFragment import com.google.android.libraries.places.widget.PlaceLoadListener import com.google.android.libraries.places.widget.model.Orientation private const val TAG = "PlacesUiKit" /** * A simple ViewModel to store UI state that needs to survive configuration changes. * In this case, it holds the ID of the selected place. Using a ViewModel is good practice * as it prevents data loss during events like screen rotation, ensuring a * seamless user experience. */ class MainViewModel : ViewModel() { var selectedPlaceId: String? = null } /** * This activity serves as a basic example of integrating the Place Details UI Kit. * It demonstrates the fundamental steps required: * 1. Setting up a Google Map. * 2. Requesting location permissions to center the map. * 3. Handling clicks on Points of Interest (POIs) to get a Place ID. * 4. Using the Place ID to load and display place details in a [PlaceDetailsCompactFragment]. */ class MainActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnPoiClickListener { // ViewBinding provides type-safe access to views defined in the XML layout, // eliminating the need for `findViewById` and preventing null pointer exceptions. private lateinit var binding: ActivityMainBinding private var googleMap: GoogleMap? = null // The FusedLocationProviderClient is the main entry point for interacting with the // fused location provider, which intelligently manages the underlying location technologies. private lateinit var fusedLocationClient: FusedLocationProviderClient // Using registerForActivityResult is the modern, recommended approach for handling // permission requests. It decouples the request from the handling logic, making the // code cleaner and easier to manage compared to the older `onRequestPermissionsResult` callback. private lateinit var requestPermissionLauncher: ActivityResultLauncher<Array<String>> // The `by viewModels()` delegate provides a lazy-initialized ViewModel scoped to this Activity. // This ensures that we get the same ViewModel instance across configuration changes. private val viewModel: MainViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // The ActivityResultLauncher is initialized here. The lambda defines the callback // that will be executed once the user responds to the permission dialog. requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions -> // We check if either fine or coarse location permission was granted. if (permissions[Manifest.permission.ACCESS_FINE_LOCATION] == true || permissions[Manifest.permission.ACCESS_COARSE_LOCATION] == true) { Log.d(TAG, "Location permission granted by user.") fetchLastLocation() } else { // If permission is denied, we inform the user and default to a known location. // This ensures the app remains functional even without location access. Log.d(TAG, "Location permission denied by user.") Toast.makeText( this, "Location permission denied. Showing default location.", Toast.LENGTH_LONG ).show() moveToSydney() } } // enableEdgeToEdge() allows the app to draw behind the system bars for a more immersive experience. enableEdgeToEdge() binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) binding.dismissButton.setOnClickListener { dismissPlaceDetails() } // --- Crucial: Initialize Places SDK --- // It's essential to initialize the Places SDK before making any other Places API calls. // This should ideally be done once, for example, in the Application's `onCreate`. val apiKey = BuildConfig.PLACES_API_KEY if (apiKey.isEmpty() || apiKey == "YOUR_API_KEY") { // A valid API key is required for the Places SDK to function. Log.e(TAG, "No api key") Toast.makeText( this, "Add your own API_KEY in local.properties", Toast.LENGTH_LONG ).show() finish() return } // `initializeWithNewPlacesApiEnabled` is used to opt-in to the new SDK version. Places.initializeWithNewPlacesApiEnabled(applicationContext, apiKey) fusedLocationClient = LocationServices.getFusedLocationProviderClient(this) // ------------------------------------ // The SupportMapFragment is the container for the map. `getMapAsync` allows us to // work with the GoogleMap object via a callback once it's fully initialized. val mapFragment = supportFragmentManager.findFragmentById(R.id.map_fragment) as SupportMapFragment? mapFragment?.getMapAsync(this) // This block handles restoration after a configuration change (e.g., screen rotation). // If a place was selected before the rotation, its ID is stored in the ViewModel. // We use this ID to immediately show the details fragment again. if (viewModel.selectedPlaceId != null) { viewModel.selectedPlaceId?.let { placeId -> Log.d(TAG, "Restoring PlaceDetailsFragment for place ID: $placeId") showPlaceDetailsFragment(placeId) } } } /** * This callback is triggered when the GoogleMap object is ready to be used. * All map setup logic should be placed here. */ override fun onMapReady(map: GoogleMap) { Log.d(TAG, "Map is ready") googleMap = map // Setting the OnPoiClickListener allows us to capture user taps on points of interest. googleMap?.setOnPoiClickListener(this) // After the map is ready, we determine the initial camera position based on location permissions. if (isLocationPermissionGranted()) { fetchLastLocation() } else { requestLocationPermissions() } } /** * A helper function to centralize the check for location permissions. */ private fun isLocationPermissionGranted(): Boolean { return ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_FINE_LOCATION ) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_COARSE_LOCATION ) == PackageManager.PERMISSION_GRANTED } /** * This function triggers the permission request flow. The result is handled by the * ActivityResultLauncher defined in `onCreate`. */ private fun requestLocationPermissions() { Log.d(TAG, "Requesting location permissions.") requestPermissionLauncher.launch( arrayOf( Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION ) ) } /** * Fetches the device's last known location. This is a fast and battery-efficient way * to get a location fix. It should only be called after verifying permissions. */ @SuppressLint("MissingPermission") private fun fetchLastLocation() { // Double-checking permissions here is a good practice, although the call sites are already guarded. if (isLocationPermissionGranted()) { fusedLocationClient.lastLocation .addOnSuccessListener { location: Location? -> if (location != null) { val userLocation = LatLng(location.latitude, location.longitude) googleMap?.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 13f)) Log.d(TAG, "Moved to user's last known location.") } else { // `lastLocation` can be null if the location has never been recorded. // In this case, we fall back to a default location. Log.d(TAG, "Last known location is null. Falling back to Sydney.") moveToSydney() } } .addOnFailureListener { // This listener handles errors in the location fetching process. Log.e(TAG, "Failed to get location.", it) moveToSydney() } } } /** * Moves the map camera to a default, hardcoded location (Sydney). * This serves as a reliable fallback. */ private fun moveToSydney() { val sydney = LatLng(-33.8688, 151.2093) googleMap?.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13f)) Log.d(TAG, "Moved to Sydney") } /** * This is the callback for the `OnPoiClickListener`. It's triggered when a user * taps a POI on the map. */ override fun onPoiClick(poi: PointOfInterest) { val placeId = poi.placeId Log.d(TAG, "Place ID: $placeId") // We save the selected place ID to the ViewModel. This is critical for surviving // configuration changes. If the user rotates the screen now, the `onCreate` // method will be able to restore the place details view. viewModel.selectedPlaceId = placeId showPlaceDetailsFragment(placeId) } /** * This function is the core of the integration. It creates, configures, and displays * the [PlaceDetailsCompactFragment]. * @param placeId The unique identifier for the place to be displayed. */ private fun showPlaceDetailsFragment(placeId: String) { Log.d(TAG, "Showing PlaceDetailsFragment for place ID: $placeId") // We manage the visibility of UI elements to provide feedback to the user. // The wrapper is shown, and a loading indicator is displayed while the data is fetched. binding.placeDetailsWrapper.visibility = View.VISIBLE binding.dismissButton.visibility = View.GONE binding.placeDetailsContainer.visibility = View.GONE binding.loadingIndicatorMain.visibility = View.VISIBLE // The Place Details widget can be displayed vertically or horizontally. // We dynamically choose the orientation based on the device's current configuration. val orientation = if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { Orientation.HORIZONTAL } else { Orientation.VERTICAL } // We create a new instance of the fragment using its factory method. // We can specify which content to show, the orientation, and a custom theme. val fragment = PlaceDetailsCompactFragment.newInstance( PlaceDetailsCompactFragment.ALL_CONTENT, // Show all available content. orientation, R.style.CustomizedPlaceDetailsTheme, ).apply { // The PlaceLoadListener provides callbacks for when the place data is successfully // loaded or when an error occurs. This is where we update our UI state. setPlaceLoadListener(object : PlaceLoadListener { override fun onSuccess(place: Place) { Log.d(TAG, "Place loaded: ${place.id}") // Once the data is loaded, we hide the loading indicator and show the fragment. binding.loadingIndicatorMain.visibility = View.GONE binding.placeDetailsContainer.visibility = View.VISIBLE binding.dismissButton.visibility = View.VISIBLE } override fun onFailure(e: Exception) { Log.e(TAG, "Place failed to load", e) // On failure, we hide the UI and notify the user. dismissPlaceDetails() Toast.makeText(this@MainActivity, "Failed to load place details.", Toast.LENGTH_SHORT).show() } }) } // We add the fragment to our layout's container view. // `commitNow()` is used to ensure the fragment is immediately added and available, // which is important because we need to call a method on it right after. supportFragmentManager .beginTransaction() .replace(binding.placeDetailsContainer.id, fragment) .commitNow() // **This is the key step**: After adding the fragment, we call `loadWithPlaceId` // to trigger the data loading process for the selected place. // We use `post` to ensure this runs after the layout has been measured, // which can prevent potential timing issues. binding.root.post { fragment.loadWithPlaceId(placeId) } } /** * Hides the place details view and clears the selected place ID from the ViewModel. */ private fun dismissPlaceDetails() { binding.placeDetailsWrapper.visibility = View.GONE // Clearing the ID in the ViewModel is important so that if the user rotates the // screen after dismissing, the details view doesn't reappear. viewModel.selectedPlaceId = null } override fun onDestroy() { super.onDestroy() // It's a good practice to nullify references to objects that have a lifecycle // tied to the activity, like the GoogleMap object, to prevent potential memory leaks. googleMap = null } }
একটি থিম তৈরি করুন
একটি খণ্ডকে ইনস্ট্যান্টিয়েট করার সময়, আপনি একটি থিম নির্দিষ্ট করতে পারেন যা যেকোনো ডিফল্ট শৈলী বৈশিষ্ট্যকে ওভাররাইড করে। যে কোনো থিম বৈশিষ্ট্য ওভাররাইড করা হয় না ডিফল্ট শৈলী ব্যবহার করে। আপনি যদি একটি অন্ধকার থিম সমর্থন করতে চান, তাহলে আপনি values-night/colors.xml
এ রঙের জন্য একটি এন্ট্রি যোগ করতে পারেন।
<style name="CustomizedPlaceDetailsTheme" parent="PlacesMaterialTheme"> <item name="placesColorPrimary">@color/app_primary_color</item> <item name="placesColorOnSurface">@color/app_color_on_surface</item> <item name="placesColorOnSurfaceVariant">@color/app_color_on_surface</item> <item name="placesTextAppearanceBodySmall">@style/app_text_appearence_small</item> <item name="placesCornerRadius">20dp</item> </style>
স্ট্যান্ডার্ড কন্টেন্ট ব্যবহার করুন
এই নমুনা মানক বিষয়বস্তু ব্যবহার করে.
val fragmentStandardContent = PlaceDetailsCompactFragment.newInstance( PlaceDetailsCompactFragment.STANDARD_CONTENT, orientation, R.style.CustomizedPlaceDetailsTheme )
নির্দিষ্ট বিষয়বস্তু কাস্টমাইজ করুন
এই নমুনাটি একটি কমপ্যাক্ট ভিউয়ের জন্য শুধুমাত্র ঠিকানা, অ্যাক্সেসযোগ্য প্রবেশদ্বার এবং মিডিয়া Content
বিকল্পগুলি নির্বাচন করে এবং সেগুলিকে CustomizedPlaceDetailsTheme
দিয়ে রেন্ডার করে৷
val placeDetailsFragment = PlaceDetailsCompactFragment.newInstance( orientation, listOf( Content.ADDRESS, Content.ACCESSIBLE_ENTRANCE, Content.MEDIA ), R.style.CustomizedPlaceDetailsTheme )
সব কন্টেন্ট ব্যবহার করুন
এই নমুনা একটি কমপ্যাক্ট ভিউ এর সমস্ত Content
বিকল্প ব্যবহার করে।
val fragmentAllContent = PlaceDetailsCompactFragment.newInstance( orientation, PlaceDetailsCompactFragment.ALL_CONTENT, R.style.CustomizedPlaceDetailsTheme )