地点界面套件:地点详情(实验性)

借助适用于地点详情的地点详情界面套件,您可以添加用于在应用中显示地点详情的单个界面组件。该界面套件可单独使用,也可与其他 Google Maps Platform API 和服务搭配使用。界面套件接受地点 ID 或纬度/经度坐标,并返回渲染的地点详情信息。
界面工具包提供了一个紧凑的视图,可水平或垂直显示。您可以通过替换默认主题的任何属性来自定义地点详情的外观。您还可以通过指定 Content
条目列表(每个条目对应于显示的地点相关信息)来自定义要包含的地点详情字段。
结算
将地点详情界面套件用于地点详情时,系统会按使用该微件加载的地点数量向您收费。如果您多次加载同一地点,则需要为每次请求付费。
启用地点界面套件
在使用地点界面套件之前,您需要:
地点详情界面套件示例
您可以通过向布局添加 fragment 来向应用添加地点详情。实例化 fragment 时,您可以自定义地点详情信息的外观和风格,以满足您的需求并与应用的外观保持一致。
您可以指定屏幕方向(水平或垂直)、主题替换项和内容。内容选项包括媒体、地址、评分、价格、类型、无障碍入口、地图链接和路线链接。[查看自定义示例]()。
val fragment = PlaceDetailsCompactFragment.newInstance( orientation, listOf(Content.ADDRESS, Content.TYPE, Content.RATING, Content.ACCESSIBLE_ENTRANCE), R.style.CustomizedPlaceDetailsTheme, ) fragment.setPlaceLoadListener(object : PlaceLoadListener { override fun onSuccess() { ... } override fun onFailure(e: Exception) { ... } }) supportFragmentManager .beginTransaction() .add(R.id.fragment_container, fragment) .commitNow() fragment.loadPlaceDetails(placeId)
PlaceDetailsCompactFragment fragment = PlaceDetailsCompactFragment.newInstance( Orientation.HORIZONTAL, Arrays.asList(Content.ADDRESS, Content.TYPE, Content.RATING, Content.ACCESSIBLE_ENTRANCE), R.style.CustomizedPlaceDetailsTheme); fragment.setPlaceLoadListener( new PlaceLoadListener() { @Override public void onSuccess() { ... } @Override public void onFailure(Exception e) { ... } }); getSupportFragmentManager() .beginTransaction() .add(R.id.fragment_container, fragment) .commitNow(); fragment.loadPlaceDetails(placeId);
自定义示例
实例化 fragment 时,您可以指定一个主题来替换任何默认样式属性。未被替换的所有主题属性均使用默认样式。如果您想支持深色主题,可以在 values-night/colors.xml
中为该颜色添加条目。
<style name="CustomizedPlaceDetailsTheme" parent="PlacesTheme"> <item name="placesColorPrimary">@color/app_primary_color</item> <item name="placesColorOnSurface">@color/app_color_on_surface</item> <item name="placesColorOnSurfaceVariant">@color/app_color_on_surface</item> <item name="placesTextAppearanceBodySmall">@style/app_text_appearence_small</item> <item name="placesCornerRadius">20dp</item> </style>
您可以自定义以下样式:
placesColorSurfaceContainerLowest
placesColorOutlineDecorative
placesColorPrimary
placesColorOnSurface
placesColorOnSurfaceVariant
placesColorSecondaryContainer
placesColorOnSecondaryContainer
placesCornerRadius
placesTextAppearanceBodySmall
placesTextAppearanceBodyMedium
placesTextAppearanceBodyLarge
placesTextAppearanceLabelLarge
placesTextAppearanceHeadlineMedium
placesColorAttributionLight
(白色、灰色和黑色的枚举)placesColorAttributionDark
(白色、灰色和黑色的枚举)
此示例自定义了标准内容。
val fragmentStandardContent = PlaceDetailsCompactFragment.newInstance( orientation, PlaceDetailsCompactFragment.STANDARD_CONTENT, R.style.BrandedPlaceDetailsTheme, )
此示例会自定义所有内容。
val fragmentAllContent = PlaceDetailsCompactFragment.newInstance( orientation, PlaceDetailsCompactFragment.ALL_CONTENT, R.style.BrandedPlaceDetailsTheme, )