Places Details UI Kit (實驗功能)

您可以使用 Place Details 的 Place Details UI 套件,新增個別 UI 元件,在應用程式中顯示地點詳細資料。UI 套件可單獨使用,也可以與其他 Google 地圖平台 API 和服務搭配使用。UI 套件會採用地點 ID 或經緯度座標,並傳回經算繪的 Place Details 資訊。
UI 套件提供精簡檢視畫面,可水平或垂直顯示。您可以提供自訂 PlaceWidgetTheme
值,自訂地點詳細資料的外觀。您也可以指定 PlaceDetailsCompactView
項目清單,自訂要納入哪些地點詳細資料欄位,每個項目都會對應至顯示的地點資訊。
帳單
使用 Place Details 的 Place Details UI Kit 時,系統會針對使用小工具載入的每個地點向您收費。如果您多次載入相同地點,系統會針對每項要求向您收費。
啟用 Places UI 套件
使用 Places UI Kit 前,您必須:
Place Details UI Kit 範例
Place Details 小工具是 Swift UI 檢視畫面。您可以根據需求自訂地點詳細資料資訊的外觀和風格,以便與應用程式外觀相符。
您可以指定方向 (水平或垂直)、主題覆寫和內容。內容選項包括媒體、地址、評分、價格、類型、無障礙入口、地圖連結和路線連結。[查看自訂範例]()。
預設位置為直向,如果您想要使用橫向版面配置,請在 PlaceDetailsCompactView
中指定 orientation: .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: .vertical, query: $query, contentType: [.media(), .address(), .rating(), .type(), .price(), .accessibleEntranceIcon(), .mapsLink(), .directionsLink()], theme: theme, placeDetailsCallback: placeDetailsCallback, preferTruncation: false ) .frame(width: 350) }
這個範例會建立使用水平版面配置的簡潔檢視畫面。
// 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) }
自訂範例
這個範例說明如何自訂預設樣式屬性。
// 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) }