Kit UI Places Details (Eksperimental)

Kit UI Place Details untuk Place Details memungkinkan Anda menambahkan komponen UI individual yang menampilkan detail tempat di aplikasi Anda. Kit UI dapat digunakan secara independen atau bersama dengan API dan layanan Google Maps Platform lainnya. Kit UI menggunakan ID Tempat atau koordinat lintang/bujur dan menampilkan informasi Place Details yang dirender.
Kit UI menawarkan tampilan ringkas, yang dapat ditampilkan secara horizontal atau vertikal. Anda dapat menyesuaikan tampilan detail tempat dengan memberikan nilai PlaceWidgetTheme
kustom. Anda juga dapat menyesuaikan kolom detail tempat yang disertakan dengan menentukan daftar entri PlaceDetailsCompactView
, yang masing-masing sesuai dengan informasi yang ditampilkan tentang tempat tersebut.
Penagihan
Saat menggunakan Place Details UI Kit untuk Place Details, Anda akan ditagih untuk setiap tempat yang dimuat menggunakan widget. Jika memuat tempat yang sama beberapa kali, Anda akan ditagih untuk setiap permintaan.
Mengaktifkan Kit UI Places
Sebelum menggunakan Places UI Kit, Anda harus:
- Buat project Cloud dengan akun penagihan.
- Aktifkan Places API untuk project Anda.
- Mendapatkan kunci API.
Contoh UI Kit Place Details
Widget Place Details adalah Tampilan UI Swift. Anda dapat menyesuaikan tampilan dan nuansa informasi detail tempat agar sesuai dengan kebutuhan dan cocok dengan tampilan aplikasi Anda.
Anda dapat menentukan orientasi (horizontal atau vertikal), penggantian tema, dan konten. Opsi kontennya adalah media, alamat, rating, harga, jenis, pintu masuk yang dapat diakses, link peta, dan link rute. [Lihat contoh penyesuaian]().
Posisi default-nya adalah vertikal. Jika Anda menginginkan tata letak horizontal, tentukan orientation: .horizontal
di PlaceDetailsCompactView
.
Contoh ini membuat tampilan ringkas dengan tata letak vertikal.
// Callback for the place details widget. let placeDetailsCallback: (PlaceDetailsResult) -> Void = { result in if let place = result.place { print("Place: \(place.description)") } else { print("Error: \(String(describing: result.error))") } } @Environment(\.colorScheme) var colorScheme var customTheme = false var theme: PlaceWidgetTheme { if customTheme { var theme = PlaceWidgetTheme() theme.colorSurfaceContainerLowest = (colorScheme == .dark ? .blue : .gray) theme.colorOutlineDecorative = (colorScheme == .dark ? .white : .black) theme.colorOnSurface = (colorScheme == .dark ? .yellow : .red) theme.colorOnSurfaceVariant = (colorScheme == .dark ? .white : .blue) theme.colorOnSecondaryContainer = (colorScheme == .dark ? .white : .red) theme.colorSecondaryContainer = (colorScheme == .dark ? .green : .purple) theme.colorPositive = (colorScheme == .dark ? .yellow : .red) theme.colorPrimary = (colorScheme == .dark ? .yellow : .purple) theme.colorInfo = (colorScheme == .dark ? .yellow : .purple) theme.cornerRadius = 10 theme.labelLarge = .system(size: 15) theme.headlineMedium = .system(size: 14) theme.bodyLarge = .system(size: 13) theme.bodyMedium = .system(size: 12) theme.bodySmall = .system(size: 11) theme.attributionColorLight = .black theme.attributionColorDark = .white return theme } else { return PlaceWidgetTheme() } } @State var query: PlaceDetailsQuery = PlaceDetailsQuery( identifier: .placeID("ChIJT7FdmYiAhYAROFOvrIxRJDU")) var body: some View { PlaceDetailsCompactView( orientation: .vertical, query: $query, contentType: [.media(), .address(), .rating(), .type(), .price(), .accessibleEntranceIcon(), .mapsLink(), .directionsLink()], theme: theme, placeDetailsCallback: placeDetailsCallback, preferTruncation: false ) .frame(width: 350) }
Contoh ini membuat tampilan ringkas dengan tata letak horizontal.
// Callback for the place details widget. let placeDetailsCallback: (PlaceDetailsResult) -> Void = { result in if let place = result.place { print("Place: \(place.description)") } else { print("Error: \(String(describing: result.error))") } } @Environment(\.colorScheme) var colorScheme var customTheme = false var theme: PlaceWidgetTheme { if customTheme { var theme = PlaceWidgetTheme() theme.colorSurfaceContainerLowest = (colorScheme == .dark ? .blue : .gray) theme.colorOutlineDecorative = (colorScheme == .dark ? .white : .black) theme.colorOnSurface = (colorScheme == .dark ? .yellow : .red) theme.colorOnSurfaceVariant = (colorScheme == .dark ? .white : .blue) theme.colorOnSecondaryContainer = (colorScheme == .dark ? .white : .red) theme.colorSecondaryContainer = (colorScheme == .dark ? .green : .purple) theme.colorPositive = (colorScheme == .dark ? .yellow : .red) theme.colorPrimary = (colorScheme == .dark ? .yellow : .purple) theme.colorInfo = (colorScheme == .dark ? .yellow : .purple) theme.cornerRadius = 10 theme.labelLarge = .system(size: 15) theme.headlineMedium = .system(size: 14) theme.bodyLarge = .system(size: 13) theme.bodyMedium = .system(size: 12) theme.bodySmall = .system(size: 11) theme.attributionColorLight = .black theme.attributionColorDark = .white return theme } else { return PlaceWidgetTheme() } } @State var query: PlaceDetailsQuery = PlaceDetailsQuery( identifier: .placeID("ChIJT7FdmYiAhYAROFOvrIxRJDU")) var body: some View { PlaceDetailsCompactView( orientation: .horizontal, query: $query, contentType: [.media(), .address(), .rating(), .type(), .price(), .accessibleEntranceIcon(), .mapsLink(), .directionsLink()], theme: theme, placeDetailsCallback: placeDetailsCallback, preferTruncation: false ) .frame(width: 350) }
Contoh penyesuaian
Contoh ini menunjukkan cara menyesuaikan atribut gaya default.
// Callback for the place details widget. let placeDetailsCallback: (PlaceDetailsResult) -> Void = { result in if let place = result.place { print("Place: \(place.description)") } else { print("Error: \(String(describing: result.error))") } } @Environment(\.colorScheme) var colorScheme var theme: PlaceWidgetTheme { var theme = PlaceWidgetTheme() theme.colorSurfaceContainerLowest = (colorScheme == .dark ? .blue : .gray) theme.colorOutlineDecorative = (colorScheme == .dark ? .white : .black) theme.colorOnSurface = (colorScheme == .dark ? .yellow : .red) theme.colorOnSurfaceVariant = (colorScheme == .dark ? .white : .blue) theme.colorOnSecondaryContainer = (colorScheme == .dark ? .white : .red) theme.colorSecondaryContainer = (colorScheme == .dark ? .green : .purple) theme.colorPositive = (colorScheme == .dark ? .yellow : .red) theme.colorPrimary = (colorScheme == .dark ? .yellow : .purple) theme.colorInfo = (colorScheme == .dark ? .yellow : .purple) theme.cornerRadius = 10 theme.labelLarge = .system(size: 15) theme.headlineMedium = .system(size: 14) theme.bodyLarge = .system(size: 13) theme.bodyMedium = .system(size: 12) theme.bodySmall = .system(size: 11) theme.attributionColorLight = .black theme.attributionColorDark = .white return theme } @State var query: PlaceDetailsQuery = PlaceDetailsQuery( identifier: .placeID("ChIJT7FdmYiAhYAROFOvrIxRJDU")) var body: some View { PlaceDetailsCompactView( orientation: .vertical, query: $query, contentType: [.media(), .address(), .rating(), .type(), .price(), .accessibleEntranceIcon(), .mapsLink(), .directionsLink()], theme: theme, placeDetailsCallback: placeDetailsCallback, preferTruncation: false ) .frame(width: 350) }