Hãy làm theo các bước sau để thiết lập tính năng tạo kiểu dựa trên dữ liệu cho các tập dữ liệu.
Lấy khoá API và bật API
Trước khi sử dụng tính năng tạo kiểu dựa trên dữ liệu cho tập dữ liệu, bạn cần có:
Dự án trên Google Cloud có tài khoản thanh toán, đồng thời cả Maps SDK cho Android và Maps Datasets API đều được bật. Để tìm hiểu thêm, hãy xem:
Trình kết xuất bản đồ được nâng cấp có trong phiên bản 18.0.0 của Maps SDK dành cho Android. Trình kết xuất này mang đến nhiều điểm cải tiến, bao gồm cả việc hỗ trợ tính năng Định kiểu bản đồ dựa trên đám mây cho Maps SDK dành cho Android.
Khi phát hành phiên bản 18.2.0 của Maps SDK cho Android, Google đã chuyển trình kết xuất mặc định từ trình kết xuất cũ sang trình kết xuất bản đồ được nâng cấp. Thay đổi này có nghĩa là trình kết xuất bản đồ được nâng cấp hiện được dùng theo mặc định trong ứng dụng của bạn khi bạn tạo một ứng dụng mới hoặc tạo lại một ứng dụng hiện có.
Tạo mã bản đồ
Để tạo mã bản đồ mới, hãy làm theo các bước trong phần Tạo mã bản đồ. Nhớ đặt Loại bản đồ thành Android.
Để định kiểu dựa trên dữ liệu cho tập dữ liệu, bạn cần có mã bản đồ. Nếu thiếu mã bản đồ hoặc bạn truyền một mã bản đồ không hợp lệ, thì tính năng tạo kiểu dựa trên dữ liệu cho các tập dữ liệu sẽ không tải được. Trong bước khắc phục sự cố, bạn có thể dùng MapCapabilities để kiểm tra xem tính năng tạo kiểu dựa trên dữ liệu cho tập dữ liệu có được hỗ trợ hay không.
Kotlin
valcapabilities:MapCapabilities=googleMap.getMapCapabilities()System.out.println("Data-driven Styling is available: "+capabilities.isDataDrivenStylingAvailable())
Java
MapCapabilitiescapabilities=googleMap.getMapCapabilities();System.out.println("Data-driven Styling is available: "+capabilities.isDataDrivenStylingAvailable());
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-05 UTC."],[[["\u003cp\u003eTo utilize data-driven styling for datasets, you'll need a Cloud project with billing enabled, the Maps SDK for Android, and the Maps Datasets API enabled.\u003c/p\u003e\n"],["\u003cp\u003eEnsure your app uses the upgraded map renderer (available since version 18.0.0 of the Maps SDK for Android) to support data-driven styling, rebuilding the app if necessary.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need to create a map ID associated with a new map style, then update your map initialization code to include this map ID.\u003c/p\u003e\n"],["\u003cp\u003eBefore applying data-driven styling, it's crucial to check for map capabilities at runtime using \u003ccode\u003eMapCapabilities\u003c/code\u003e and provide fallback options for unsupported devices.\u003c/p\u003e\n"],["\u003cp\u003eData-driven styling requires a valid map ID; if missing or invalid, the styling will fail to load.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-datasets/start \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-datasets/start \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-datasets/start \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nFollow these steps to get set up with data-driven styling for datasets.\n\nGet an API key and enable APIs\n\nBefore using data-driven styling for datasets, you need:\nCloud project with a billing account, and both the\nMaps SDK for Android and the Maps Datasets API\nenabled. To learn more, see:\n\n- [Set up your Google Cloud project](/maps/documentation/android-sdk/cloud-setup)\n\n- [Enable Maps SDK for Android and get an API key](/maps/documentation/android-sdk/get-api-key)\n\n- [Enable the Maps Datasets API](https://console.cloud.google.com/apis/library/mapsplatformdatasets.googleapis.com)\n\nEnable the new maps renderer\n\nAn upgraded map renderer is available as of version 18.0.0 of the\nMaps SDK for Android. This renderer brings many improvements, including\nsupport for Cloud-based maps styling, to Maps SDK for Android.\n\nWith the release of version 18.2.0 of the Maps SDK for Android, Google switched the\ndefault renderer from the legacy renderer to the upgraded map renderer. This\nchange means that the upgraded map renderer is now used by default in your app\nwhen you build a new app or rebuild an existing app.\n| **Caution:** To use data-driven styling for datasets in your app, your app must be built using the upgraded map renderer. If you are adding data-driven styling for datasets to an existing app, rebuild the app to use the upgraded map renderer. For more information, see [New Map Renderer](/maps/documentation/android-sdk/renderer).\n\nCreate a map ID\n\nTo create a new map ID, follow the steps at\n[Create a map ID](/maps/documentation/get-map-id#create-a-map-id). Be sure to\nset the Map type to **Android**.\n\nCreate a new map style\n\nTo create a new map style, follow the instructions in\n[Create and use map styles](/maps/documentation/android-sdk/cloud-customization/map-styles)\nto create the style, and\n[associate the style with the map ID you just created](/maps/documentation/android-sdk/cloud-customization/map-styles#associate-style-with-map-id).\n\nUpdate your map initialization code\n\nThis step requires the map ID you just created. It can be found on your\n[Maps Management](https://console.cloud.google.com/google/maps-apis/studio/maps) page.\n\nTo add the map ID to your initialization code, see\n[Add the map ID to your app](/maps/documentation/get-map-id#add-a-map-id-to-your-app).\n\nCheck map capabilities (required)\n\nData-driven styling for datasets requires a map ID. If the map ID is missing, or an\ninvalid map ID is passed, data-driven styling for datasets cannot load. As a\ntroubleshooting step, you can use\n[`MapCapabilities`](/android/reference/com/google/android/gms/maps/model/MapCapabilities)\nto check if data-driven styling for datasets is supported.\n| **Caution:** Some devices might not support the new map renderer and therefore cannot display data-driven styling for datasets. You must use `MapCapabilities` to check for support at runtime. If data-driven styling for datasets is not supported, define a fallback option. For device requirements for the new map renderer, see [Supported\ndevices](/maps/documentation/android-sdk/renderer#supported-devices). \n\nKotlin\n\n\n```java\nval capabilities: MapCapabilities = googleMap.getMapCapabilities()\nSystem.out.println(\"Data-driven Styling is available: \" + capabilities.isDataDrivenStylingAvailable())\n```\n\n\u003cbr /\u003e\n\nJava\n\n\n```java\nMapCapabilities capabilities = googleMap.getMapCapabilities();\nSystem.out.println(\"Data-driven Styling is available: \" + capabilities.isDataDrivenStylingAvailable());\n```\n\n\u003cbr /\u003e\n\nNext steps\n\n- [Create and manage a dataset](/maps/documentation/android-sdk/dds-datasets/create-dataset)"]]