प्लैटफ़ॉर्म चुनें: Android iOS JavaScript

Place Search कॉम्पोनेंट

Places UI Kit का Place Search कॉम्पोनेंट, किसी जगह की खोज के नतीजों को सूची में दिखाता है.

Places UI Kit Place Search कॉम्पोनेंट

जगह के हिसाब से खोज करने की सुविधा के लिए, सूची को पसंद के मुताबिक बनाया जा सकता है. इनके लिए वैल्यू तय की जा सकती है:

  • दिखाने के लिए कॉन्टेंट
  • वर्टिकल ओरिएंटेशन में मीडिया का साइज़
  • टेक्स्ट में काट-छांट
  • ओरिएंटेशन
  • थीम को बदलने की ऐसी सुविधाएं जो आपके ब्रैंड और ऐप्लिकेशन की डिज़ाइन लैंग्वेज से मेल खाती हों
  • एट्रिब्यूशन की स्थिति
  • कोई जगह चुनी जा सकती है या नहीं

अनुरोध को पसंद के मुताबिक बनाया जा सकता है, ताकि SearchByTextRequest या SearchNearbyRequest में से कोई एक कार्रवाई की जा सके.

बिलिंग

SearchByTextRequest() या PlaceSearchViewRequest() एट्रिब्यूट की वैल्यू बदलने पर, आपसे हर बार शुल्क लिया जाता है.

अपने ऐप्लिकेशन में जगह की जानकारी खोजने की सुविधा जोड़ना

PlaceSearchView class का इस्तेमाल करके, जगह के हिसाब से खोज करने वाला विजेट जोड़ें.

Swift

PlaceSearchView(
      orientation: .horizontal, // default is vertical
      request: $placeSearchViewRequest,
      configuration: configuration
)

जब आपको अपने ऐप्लिकेशन में टेक्स्ट खोज या आस-पास की खोज का नतीजा लोड करना हो, तब PlaceSearchViewRequest वैल्यू अपडेट करें.

Swift

// use placeSearchViewRequest = .searchNearby(...) to  configure a searchNearby request

  @State private var let placeSearchViewRequest = .searchByText(
    SearchByTextRequest(
      textQuery: "Googleplex",
      placeProperties: [.all],
      locationBias: CircularCoordinateRegion(
        center: CLLocationCoordinate2D(latitude: 0, longitude: 0),
        radius: 0
      )
    )
  )
    

इसके अलावा, कॉम्पोनेंट लोड होने, किसी जगह को चुने जाने या कॉम्पोनेंट लोड करने में गड़बड़ी होने पर, आपको कॉलबैक मिल सकते हैं. हालांकि, ऐसा करना ज़रूरी नहीं है.

Swift

.onLoad { places in
  print("places: \(places)")
}
.onRequestError { error in
  print("error: \(error)")
}
.onPlaceSelected { place in
  print("place: \(place)")
}
    

Place Search कॉम्पोनेंट को पसंद के मुताबिक बनाना

कॉन्टेंट को पसंद के मुताबिक बनाना

आपको यह बताना होगा कि आपका कॉम्पोनेंट कौनसा कॉन्टेंट दिखाएगा.

इस उदाहरण में, कॉम्पोनेंट को कॉन्फ़िगर किया गया है, ताकि जगह का पता और रेटिंग दिखाई जा सके.

Swift

private let configuration = PlaceSearchConfiguration(
    content: [.address(), .rating()]
)

आपके पास, जगह के हिसाब से खोज करने की सुविधा देने वाले कॉम्पोनेंट में दिखने वाले कॉन्टेंट के इन पहलुओं को अपनी पसंद के मुताबिक बनाने का विकल्प भी होता है:

  • content: कॉम्पोनेंट में दिखाया गया कॉन्टेंट.
  • mediaSize: फ़्रैगमेंट के वर्टिकल ओरिएंटेशन में फ़ोटो का साइज़. डिफ़ॉल्ट रूप से, यह छोटा होता है. कॉन्टेंट में बताया गया हो.
  • preferTruncation: इससे यह तय होता है कि जगह की जानकारी वाले हर व्यू के टेक्स्ट को छोटा करना है या नहीं. डिफ़ॉल्ट रूप से, यह 'गलत' पर सेट होता है.
  • theme: आपकी कस्टम थीम, जो PlacesMaterialTheme से इनहेरिट करती है. थीम के बारे में ज़्यादा जानें.
  • attributionPosition: Google Maps एट्रिब्यूशन को कॉम्पोनेंट के सबसे ऊपर या सबसे नीचे दिखाना है या नहीं. डिफ़ॉल्ट वैल्यू .top होती है.
  • selectable: इससे पता चलता है कि सूची में मौजूद हर जगह को चुना जा सकता है या नहीं. अगर इसे चुना जा सकता है, तो जगह चुनने के बाद onPlaceSelected क्लोज़र को कॉल किया जाएगा. डिफ़ॉल्ट रूप से, यह 'गलत' पर सेट होता है.

PlaceSearchConfiguration में, पसंद के मुताबिक बनाने के लिए कॉन्फ़िगरेशन जोड़ें.

Swift

private let configuration = PlaceSearchConfiguration(
    content: [.address, .rating, .media(size: .large)],
    preferTruncation: true, // default is false
    theme: PlacesMaterialTheme(),
    attributionPosition: .bottom, // default is top
    selectable: true // default is false
)
        

ओरिएंटेशन को पसंद के मुताबिक बनाना

डिफ़ॉल्ट ओरिएंटेशन वर्टिकल होता है. PlaceSearchView में हॉरिज़ॉन्टल ओरिएंटेशन तय किया जा सकता है.

Swift

PlaceSearchView(
      orientation: .horizontal, // default is vertical
      request: $placeSearchViewRequest,
      configuration: configuration
)
        

थीम को पसंद के मुताबिक बनाना

ऐसी थीम तय की जा सकती है जो स्टाइल एट्रिब्यूट के किसी भी डिफ़ॉल्ट एट्रिब्यूट को बदल दे. डिफ़ॉल्ट वैल्यू PlacesMaterialTheme होती है.

थीमिंग के बारे में ज़्यादा जानने के लिए, कस्टम स्टाइलिंग सेक्शन देखें.

Places यूआई किट में, डिफ़ॉल्ट रूप से गहरे रंग वाली थीम उपलब्ध होती है. इसलिए, आपको गहरे और हल्के, दोनों रंग वाली थीम को पसंद के मुताबिक बनाना पड़ सकता है. गहरे रंग की थीम को पसंद के मुताबिक बनाने के लिए, अपनी कस्टम थीम में .dark और attribution.darkModeColor की वैल्यू जोड़ें.

उदाहरण

Place Search कॉम्पोनेंट जोड़ना

Swift

struct PlaceSearchDemoView: View {
  private let configuration = PlaceSearchConfiguration(
    content: [.address(), .rating(), .type(), .media(size: .large)],
    preferTruncation: true,  // default is false
    theme: PlacesMaterialTheme(),
    attributionPosition: .bottom,  // default is top
    selectable: true  // default is false
  )
  // can also do let placeSearchViewRequest = .searchNearby(...) to  configure a searchNearby request
  @State private var placeSearchViewRequest: PlaceSearchViewRequest = .searchByText(
    SearchByTextRequest(
      textQuery: "Googleplex",
      placeProperties: [.all],
      locationBias: CircularCoordinateRegion(
        center: CLLocationCoordinate2D(latitude: 0, longitude: 0),
        radius: 0
      )
    )
  )
  var body: some View {
    PlaceSearchView(
      orientation: .horizontal,  // default is vertical
      request: $placeSearchViewRequest,
      configuration: configuration
    )
    .onLoad { places in
      print("places: \(places)")
    }
    .onRequestError { error in
      print("error: \(error)")
    }
    .onPlaceSelected { place in
      print("place: \(place)")
    }
  }
}
    

थीम को पसंद के मुताबिक बनाना

Places यूआई किट में, डिफ़ॉल्ट रूप से गहरे रंग वाली थीम उपलब्ध होती है. इसलिए, आपको गहरे और हल्के, दोनों रंग वाली थीम को पसंद के मुताबिक बनाना पड़ सकता है. गहरे रंग की थीम को पसंद के मुताबिक बनाने के लिए, अपनी कस्टम थीम में .dark और attribution.darkModeColor की वैल्यू जोड़ें.

Swift

@Environment(\.colorScheme) var colorScheme
var theme: PlacesMaterialTheme {
    if customTheme {
      var theme = PlacesMaterialTheme()
      var color = PlacesMaterialColor()
      color.surface = (colorScheme == .dark ? .blue : .gray)
      color.outlineDecorative = (colorScheme == .dark ? .white : .black)
      color.onSurface = (colorScheme == .dark ? .yellow : .red)
      color.onSurfaceVariant = (colorScheme == .dark ? .white : .blue)
      color.onSecondaryContainer = (colorScheme == .dark ? .white : .red)
      color.secondaryContainer = (colorScheme == .dark ? .green : .purple)
      color.positive = (colorScheme == .dark ? .yellow : .red)
      color.primary = (colorScheme == .dark ? .yellow : .purple)
      color.info = (colorScheme == .dark ? .yellow : .purple)
      var shape = PlacesMaterialShape()
      shape.cornerRadius = 10
      var font = PlacesMaterialFont()
      font.labelLarge = .system(size: UIFontMetrics.default.scaledValue(for: 18))
      font.headlineMedium = .system(size: UIFontMetrics.default.scaledValue(for: 15))
      font.bodyLarge = .system(size: UIFontMetrics.default.scaledValue(for: 15))
      font.bodyMedium = .system(size: UIFontMetrics.default.scaledValue(for: 12))
      font.bodySmall = .system(size: UIFontMetrics.default.scaledValue(for: 11))
      var attribution = PlacesMaterialAttribution()
      attribution.lightModeColor = .black
      attribution.darkModeColor = .white
      theme.color = color
      theme.shape = shape
      theme.font = font
      theme.attribution = attribution
    } else {
      return PlacesMaterialTheme()
    }
}