চিহ্নিতকারী উপাদান স্থাপন করুন

প্লেস মার্কারস কম্পোনেন্টটি আপনাকে কাস্টমাইজযোগ্য ম্যাপ অ্যানোটেশন তৈরি করার সুযোগ দেয়, যা সরাসরি ম্যাপের উপর কোনো স্থানের গুরুত্বপূর্ণ তথ্য প্রদর্শন করে। আপনি কোনো স্থানের রেটিং, স্থানের ধরন, খোলা বা বন্ধ অবস্থা, মূল্যের পরিসীমা, অথবা নিজস্ব টেক্সট (যেমন, এআই-দ্বারা তৈরি কোনো লেবেল বা ভ্রমণপথ নম্বর)-এর মতো বিষয়বস্তু প্রদর্শন করতে পারেন। এর ফলে আপনার ব্যবহারকারীরা কোনো বিস্তারিত প্লেস কার্ডে ট্যাপ না করেই ম্যাপ অন্বেষণের আরও তথ্যপূর্ণ অভিজ্ঞতা লাভ করেন।

স্থান চিহ্নিতকারীগুলির জন্য উপলব্ধ আইকন এবং লেখা

প্রতিটি PlaceMarker জন্য আপনি একটি মার্কার আইকন এবং ঐচ্ছিক মার্কার টেক্সট প্রদর্শন করতে পারেন।

উপলব্ধ আইকনগুলো হলো:

  • Type : স্থানের ধরণ।
  • None : কোনো আইকন নেই।
উপলব্ধ টেক্সট মার্কারগুলো হলো:
  • Rating : প্রাপ্ত নম্বর।
  • PriceRange : মূল্যের পরিসর (উদাহরণস্বরূপ, $১০-২০)।
  • OpenStatus : ব্যবসাটি খোলা না বন্ধ।
  • Custom : নিজস্ব লেখা (উদাহরণস্বরূপ, "জনপ্রিয়")।

স্থান আইডি ( PlaceId ), রিসোর্স নাম ( ResourceName ), বা ভৌগোলিক স্থানাঙ্ক ( Coordinates ) ব্যবহার করে স্থানটিকে উল্লেখ করুন।

প্রদর্শন এবং অ্যাট্রিবিউশন প্রয়োজনীয়তা

যখন Places UI Kit ম্যাপ মার্কারগুলো প্রদর্শিত হয়, তখন মার্কারগুলো বিচ্ছিন্নভাবে দেখানো যাবে না। প্রয়োজনীয় গুগল ব্র্যান্ডিং, অবদানকারীর স্বীকৃতি এবং ‘সমস্যা রিপোর্ট করুন’ ফ্লো প্রদানের জন্য সেগুলোকে অবশ্যই ইন্টারেক্টিভ হতে হবে এবং ক্লিক বা ট্যাপ করলে একটি সংশ্লিষ্ট Place Details Component বা Lightbox খুলতে হবে।

যেসব ক্ষেত্রে স্থান সীমিত, সেসব ক্ষেত্রে আমাদের ছবি ও পর্যালোচনার কৃতিত্ব প্রদানের শর্তাবলী দেখুন।

স্থান চিহ্নিতকারীর উদাহরণ

ভিউ-টু-কম্পোজ র‍্যাপারের অতিরিক্ত বোঝা দূর করতে এবং থিম অমিলের সমস্যা এড়াতে আমরা জেটপ্যাক কম্পোজের @Composable ফাংশন সরবরাহ করি।

মৌলিক মার্কার কাস্টমাইজেশন

নিম্নলিখিত কোড উদাহরণটি প্লেস মার্কারের মৌলিক কাস্টমাইজেশন প্রদর্শন করে, যার মধ্যে ডিফল্ট মার্কারের জন্য ত্রিভুজাকার স্পিচ বাবলের ঠোঁটটি লুকানোও অন্তর্ভুক্ত।

কোটলিন

import androidx.compose.runtime.Composable
import com.google.android.libraries.places.compose.PlaceMarker
import com.google.android.libraries.places.compose.marker.MarkerIcon
import com.google.android.libraries.places.compose.marker.MarkerText
import com.google.android.libraries.places.compose.PlaceReference

@Composable
fun DefaultMarker() {
    PlaceMarker(
        reference = PlaceReference.PlaceId("PLACE_ID"),
        icon = MarkerIcon.None,
        beakPresence = false, // remove beak
    )
}

@Composable
fun RatingMarker() {
    PlaceMarker(
        reference = PlaceReference.PlaceId("PLACE_ID"),
        icon = MarkerIcon.None,
        text = MarkerText.Rating
    )
}

@Composable
fun TypeAndRatingMarker() {
    PlaceMarker(
        reference = PlaceReference.PlaceId("PLACE_ID"),
        icon = MarkerIcon.Type,
        text = MarkerText.Rating

    )
}

@Composable
fun PriceRangeMarker() {
    PlaceMarker(
        reference = PlaceReference.ResourceName("places/PLACE_RESOURCE_NAME"),
        icon = MarkerIcon.None,
        text = MarkerText.PriceRange
    )
}

@Composable
fun OpenStatusMarker() {
   PlaceMarker(
       reference = PlaceReference.Coordinates(latitude = 37.7749, longitude = -122.4194),
        icon = MarkerIcon.None,
        text = MarkerText.OpenStatus
   )
}

@Composable
fun CustomTextMarker() {
    PlaceMarker(
        reference = PlaceReference.PlaceId("PLACE_ID"),
        icon = MarkerIcon.None,
        // Custom text accepts a String to display a number (e.g. "3") or text (e.g. "NEW")
        text = MarkerText.Custom("NEW")
    )
}

একটি ক্লিক লিসেনার তৈরি করুন

একটি স্বতন্ত্র মার্কার ট্যাপ করা হলে কাস্টম অ্যাকশন ট্রিগার করার জন্য আপনি একটি onClick কলব্যাক প্রদান করতে পারেন। তবে, যখন মার্কারটি একটি ম্যাপে রেন্ডার করা হয় (উদাহরণস্বরূপ, একটি MarkerComposable ভিতরে), তখন ট্যাপ ইভেন্টগুলো ম্যাপ দ্বারা ইন্টারসেপ্ট করা হয়। এই ক্ষেত্রে, আপনাকে মার্কারের onClick হ্যান্ডলারের পরিবর্তে MarkerComposable এর onClick হ্যান্ডলার ব্যবহার করতে হবে।

নিম্নলিখিত কোড উদাহরণটিতে দেখানো হয়েছে কিভাবে MarkerComposable এর onClick হ্যান্ডলার ব্যবহার করতে হয়।

কোটলিন

import android.util.Log
import androidx.compose.runtime.Composable
import com.google.android.libraries.places.compose.PlaceMarker
import com.google.android.libraries.places.compose.marker.MarkerIcon
import com.google.android.libraries.places.compose.PlaceReference


/**
 * PlaceMarker used outside of a map (e.g. in a list, bottom sheet, or custom overlay).
 *
 * There is no host component that provides a default click behavior here, so PlaceMarker's own
 * `onClick` is the only way for a developer to react to a tap. This is why `onClick` must stay
 * on the PlaceMarker API.
 */
@Composable
fun ClickableMarkerWithCustomConfig() {
   PlaceMarker(
       reference = PlaceReference.PlaceId("PLACE_ID"),
       icon = MarkerIcon.Type,
       
       onClick = { place ->
           openPlaceCard(place.id) // developer might want to open the place card
           Log.i("PlacesMarker", "Marker was tapped by user!")
       }
   )
}

/**
 * PlaceMarker used as the content of a MarkerComposable on a GoogleMap.
 *
 * MarkerComposable does NOT add PlaceMarker to the touch-input hierarchy: it snapshots the
 * composable into a bitmap and hands that bitmap to the Maps renderer as the marker icon. The
 * rendered marker is a map object, not a Compose node, so:
 *
 *   - PlaceMarker's own `onClick` would never be invoked here (no touch events ever reach it).
 *   - The tap is delivered by the Maps SDK to MarkerComposable's `onClick`, which is the only
 *     click entry point on a map.
 *
 * Accordingly, the state-based `PlaceMarker(state = ...)` overload used below deliberately does
 * not expose an `onClick` parameter, so the correct handler is the only one available.
 */
@Composable
fun PlaceMarkerOnMap(markerState: PlaceMarkerState) {
  GoogleMap(
    modifier = Modifier.fillMaxSize(),
    cameraPositionState = rememberCameraPositionState(),
  ) {
    markerState.location?.let { position ->
      MarkerComposable(
        state = rememberUpdatedMarkerState(position = position),
        // this is the click handler for the map use case.
        onClick = {
          markerState.place?.let { place -> openPlaceCard(place.id) }
          true // consume the event
        },
      ) {
        PlaceMarker(state = markerState)
      }
    }
  }
}

লোড স্ট্যাটাস এবং কলব্যাকগুলি পরিচালনা করুন

নিম্নলিখিত কোড উদাহরণটি দেখায় কিভাবে রেন্ডারিং বা অনুপস্থিত ডেটার ত্রুটিগুলি পরিচালনা করার জন্য কলব্যাক সরবরাহ করতে হয়।

কোটলিন

import android.util.Log
import androidx.compose.runtime.Composable
import com.google.android.libraries.places.compose.PlaceMarker
import com.google.android.libraries.places.compose.marker.MarkerIcon
import com.google.android.libraries.places.compose.PlaceReference

@Composable
fun StatusHandlingMarker() {
    PlaceMarker(
        reference = PlaceReference.PlaceId("PLACE_ID"),
        icon = MarkerIcon.Type,
        // Triggered when attribute data is successfully fetched and the marker is rendered.
        // Returns a minimal Place object with ID, location (LatLng), and viewport fields set.
        onMarkerLoaded = { place ->
            Log.i("PlacesMarker", "Marker successfully loaded for place ID: ${place.id}")
        },
        // Triggered when data fetching fails or required attribute data is missing for the place.
        // Returns an optional Place object and an Exception describing the root cause.
        onMarkerLoadFailed = { place, exception ->
            Log.e("PlacesMarker", "Failed to load marker for place ID: ${place?.id}", exception)
        }
    )
}

মানচিত্রে মার্কার স্থাপন করতে PlaceMarkerState ব্যবহার করুন

মার্কারটি কোথায় রাখবেন তা ঠিক করতে সাহায্য করার জন্য লোকেশন এবং ভিউপোর্ট সহ Place অবজেক্টটি ফেরত দেওয়া হয়।

কোটলিন

// Step 1: Obtain configured handle in a single 1-line call (PlaceMarker mounted internally)
val markerState = rememberPlaceMarkerState(
  reference = PlaceReference.PlaceId(placeId),
  icon = MarkerIcon.Type
)

// Step 2: Pass PlaceMarkerState.location and PlaceMarker(state = PlaceMarkerState) directly to the map marker
GoogleMap(...) {
  markerState.location?.let { position ->
    MarkerComposable(
      state = rememberMarkerState(position = position),
      onClick = {
        markerState.place?.let { place ->
          // Handle marker click
        }
        true
      }
    ) {
      PlaceMarker(state = markerState) // Render marker UI content directly on map canvas
    }
  }
}

মার্কারটিকে আপনার পছন্দমতো আকারে স্কেল করুন

কোটলিন

// Off the map: scale with a one-line modifier.
// Modifier.scale is a draw-time transform, so the bubble, beak, icon and text all scale together.
@Composable
fun ScaledMarker() {
  PlaceMarker(
    reference = PlaceReference.PlaceId(placeId),
    icon = MarkerIcon.Type,
    text = MarkerText.Rating,
    modifier = Modifier.scale(2.1f),
  )
}

// On the map: scale by overriding LocalDensity.
// MarkerComposable snapshots its content into a marker bitmap sized to the measured layout bounds.
// Modifier.scale does not change those bounds, so the marker would be clipped and blurry. Scaling
// the density re-measures every dp and sp inside the marker, so the bitmap, the layout bounds and
// the map hit target all grow with it.
@Composable
fun ScaledMarkerOnMap(markerState: PlaceMarkerState) {
  val density = LocalDensity.current
  val scaledDensity = remember(density) {
    Density(density = density.density * 2.1f, fontScale = density.fontScale * 2.1f)
  }
  GoogleMap(...) {
    markerState.location?.let { position ->
      MarkerComposable(
        state = rememberUpdatedMarkerState(position = position),
        anchor = Offset(0.5f, 1.0f),
      ) {
        CompositionLocalProvider(LocalDensity provides scaledDensity) {
          PlaceMarker(state = markerState)
        }
      }
    }
  }
}