Place Search कॉम्पोनेंट
जगहों की जानकारी देने वाली यूआई किट का Place Search कॉम्पोनेंट, किसी जगह की खोज के नतीजों को सूची में दिखाता है.

जगह की खोज करने की सूची को पसंद के मुताबिक बनाया जा सकता है. इनमें से कोई भी विकल्प चुना जा सकता है:
- दिखाने के लिए कॉन्टेंट
- वर्टिकल ओरिएंटेशन में मीडिया का साइज़
- टेक्स्ट में काट-छांट
- ओरिएंटेशन
- आपके ब्रैंड और ऐप्लिकेशन की डिज़ाइन लैंग्वेज से मेल खाने वाली थीम ओवरराइड
- एट्रिब्यूशन की स्थिति
- यह जानकारी कि किसी जगह को चुना जा सकता है या नहीं
अनुरोध को अपनी ज़रूरत के हिसाब से भी बदला जा सकता है, ताकि Search by text request
या Search Nearby request
में से कोई एक कार्रवाई की जा सके.
बिलिंग
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
पर सेट होता है. थीमिंग के बारे में ज़्यादा जानने के लिए, जगह की जानकारी दिखाने वाले कॉम्पोनेंट का दस्तावेज़ देखें.
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() } }
उदाहरण
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)") } } }