Sınırlar için veriye dayalı stil oluşturma özelliğini kullanmaya başlamak üzere aşağıdaki adımları uygulayın.
Yeni harita oluşturucuyu etkinleştirme
Android için Haritalar SDK'sının 18.0.0 sürümünden itibaren yükseltilmiş bir harita oluşturucu kullanılabilir. Bu oluşturucu, Android için Haritalar SDK'sına bulut tabanlı harita stili desteği gibi birçok iyileştirme getiriyor.
Android için Haritalar SDK'sının 18.2.0 sürümünün yayınlanmasıyla birlikte Google, varsayılan oluşturucuyu eski oluşturucudan yeni sürüme geçirilen harita oluşturucuya değiştirdi. Bu değişiklik, yeni bir uygulama oluşturduğunuzda veya mevcut bir uygulamayı yeniden oluşturduğunuzda yükseltilmiş harita oluşturucunun artık uygulamanızda varsayılan olarak kullanılacağı anlamına gelir.
Harita kimliği oluşturma
Yeni bir harita kimliği oluşturmak için Harita kimliği oluşturma başlıklı makaledeki adımları uygulayın. Harita türünü Android olarak ayarladığınızdan emin olun.
Yeni harita stilinizdeki özellik katmanlarını seçin
Google API Konsolu'nda yeni harita stiliniz için hangi özellik katmanlarının gösterileceğini seçebilirsiniz. Özellik katmanı, haritada hangi tür sınırların (ör. yerleşim yerleri, eyaletler vb.) görüneceğini belirler.
Posta kodu veya yerellik özellik katmanı gibi bir haritanın her bir özellik katmanını temsil etmek için FeatureLayer nesnesi kullanırsınız. Bir özellik katmanı nesnesine erişmek için harita başlatıldığında GoogleMap.getFeatureLayer() işlevini çağırın:
Java
privateFeatureLayerpostalCodeLayer; @OverridepublicvoidonMapReady(GoogleMapmap){// Get the POSTAL_CODE feature layer.postalCodeLayer=map.getFeatureLayer(newFeatureLayerOptions.Builder().featureType(FeatureType.POSTAL_CODE).build());...}
Kotlin
privatevarpostalCodeLayer:FeatureLayer?=null overridefunonMapReady(googleMap:GoogleMap){// Get the POSTAL_CODE feature layer.postalCodeLayer=googleMap.getFeatureLayer(newFeatureLayerOptions.Builder().featureType(FeatureType.POSTAL_CODE).build())...}
Özellik katmanının türünü belirtmek için getFeatureLayer()'e bir FeatureLayerOptions nesnesi iletin. Bu örnekte, POSTAL_CODE katmanına erişmek istiyorsunuz. Stil vermek istediğiniz her katman için farklı bir FeatureLayer nesnesi oluşturun.
FeatureLayer nesnesini aldıktan sonra bu özellikteki sınır poligonlarına stil uygulayabilirsiniz.
Harita özelliklerini kontrol edin (zorunlu)
Sınırlar için veriye dayalı stil oluşturma özelliği, harita kimliği gerektirir. Harita kimliği eksikse veya geçersiz bir harita kimliği iletilirse sınırlar için veriye dayalı stil oluşturma yüklenemez. Sorun giderme adımı olarak, sınırların veriye dayalı stilinin desteklenip desteklenmediğini kontrol etmek için MapCapabilities kullanabilirsiniz.
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());
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 2025-09-05 UTC."],[[["\u003cp\u003eData-driven styling for boundaries requires using the upgraded map renderer (available since Maps SDK for Android v18.0.0) and creating a map ID with an associated map style.\u003c/p\u003e\n"],["\u003cp\u003eYou can select specific boundary feature layers (like Postal Code or Locality) to display on your map by customizing your map style in the Google Cloud Console, optimizing for performance by choosing only necessary layers.\u003c/p\u003e\n"],["\u003cp\u003eTo apply data-driven styling, get access to feature layers via \u003ccode\u003eGoogleMap.getFeatureLayer()\u003c/code\u003e with \u003ccode\u003eFeatureLayerOptions\u003c/code\u003e defining the desired layer type, and style them individually.\u003c/p\u003e\n"],["\u003cp\u003eBefore implementing data-driven styling, it's crucial to check for device compatibility using \u003ccode\u003eMapCapabilities.isDataDrivenStylingAvailable()\u003c/code\u003e at runtime and provide a fallback in case it's not supported.\u003c/p\u003e\n"]]],[],null,["# Get started\n\nSelect platform: [Android](/maps/documentation/android-sdk/dds-boundaries/start \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-boundaries/start \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-boundaries/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 boundaries.\n\nEnable the new maps renderer\n----------------------------\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 boundaries in your app, your app must be built using the upgraded map renderer. If you are adding data-driven styling for boundaries to an existing app, ensure that you rebuild the app so that your app uses the upgraded map renderer. For more information, see [New Map Renderer](/maps/documentation/android-sdk/renderer).\n\nCreate a map ID\n---------------\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). Make sure you\nset the Map type to **Android**.\n\nCreate a new map style\n----------------------\n\nTo create a new map style, follow the instructions in [Manage map styles](/maps/documentation/android-sdk/cloud-customization/map-styles)\nto create the style, and [associate the style with the map ID you just created](/maps/documentation/android-sdk/cloud-customization/map-styles#associate-style-with-map-id).\n| **Experimental:** This feature can only be set for light map styles. When you link a light map style that has this feature enabled to a [map\n| ID](../map-ids/mapid-over), the enabled layers are also available for the dark map style.\n\n### Select the feature layers in your new map style\n\nIn the Google API Console you can select which feature layers to display for\nyour new map style. The feature layer determines which kinds of boundaries\nappear on the map (for example localities, states, and so on).\n| **Important:** For optimal performance, only select the layers you need.\n\n1. In the Google API Console, [go to the Map Styles page](https://console.cloud.google.com/project/_/google/maps-apis/studio/styles).\n2. Select a project if prompted.\n3. Select a map style.\n4. Click the **Feature layers** drop-down to add or remove layers.\n5. Click **Save** to save your changes and make them available to your maps.\n\nUpdate your map initialization code\n-----------------------------------\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\nGet access to a feature layer of a map\n--------------------------------------\n\nYou use a [`FeatureLayer`](/android/reference/com/google/android/gms/maps/model/FeatureLayer)\nobject to represent each feature layer of a map, such as a Postal Code or\nLocality feature layer. To get access to a feature layer object, call\n[`GoogleMap.getFeatureLayer()`](/android/reference/com/google/android/gms/maps/GoogleMap#getFeatureLayer(com.google.android.gms.maps.model.FeatureLayerOptions))\nwhen the map initializes: \n\n### Java\n\n\n```javascript\nprivate FeatureLayer postalCodeLayer;\n\n@Override\npublic void onMapReady(GoogleMap map) {\n // Get the POSTAL_CODE feature layer.\n postalCodeLayer = map.getFeatureLayer(new FeatureLayerOptions.Builder()\n .featureType(FeatureType.POSTAL_CODE)\n .build());\n ...\n}\n```\n\n\u003cbr /\u003e\n\n### Kotlin\n\n\n```java\nprivate var postalCodeLayer: FeatureLayer? = null\n\noverride fun onMapReady(googleMap: GoogleMap) {\n // Get the POSTAL_CODE feature layer.\n postalCodeLayer = googleMap.getFeatureLayer(new FeatureLayerOptions.Builder()\n .featureType(FeatureType.POSTAL_CODE)\n .build())\n ...\n}\n```\n\n\u003cbr /\u003e\n\nPass a [`FeatureLayerOptions`](/android/reference/com/google/android/gms/maps/model/FeatureLayerOptions)\nobject to `getFeatureLayer()` to specify the type of the feature layer. In this\nexample, you want to access the `POSTAL_CODE` layer. Create a different\n`FeatureLayer` object for each layer that you want to style.\n\nOnce you have the `FeatureLayer` object, you can apply styling to the\nboundary polygons in that feature.\n| **Note:** If a `FeatureLayer` of the specified type does not exist for the map, or if data-driven styling for boundaries is not enabled because you have not specified the map ID, this call returns but logs an error. Use the [`FeatureLayer.isAvailable()`](/android/reference/com/google/android/gms/maps/model/FeatureLayer#isAvailable()) method to determine if a `FeatureLayer` is available.\n\nCheck map capabilities (required)\n---------------------------------\n\nData-driven styling for boundaries requires a map ID. If the map ID is missing, or an\ninvalid map ID is passed, data-driven styling for boundaries 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 boundaries is supported.\n| **Caution:** Some devices might not support the new map renderer and therefore cannot display data-driven styling for boundaries. You must use `MapCapabilities` to check for support at runtime. If data-driven styling for boundaries 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\n### Kotlin\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\n### Java\n\n\n```java\nMapCapabilities capabilities = googleMap.getMapCapabilities();\nSystem.out.println(\"Data-driven Styling is available: \" + capabilities.isDataDrivenStylingAvailable());\n```\n\n\u003cbr /\u003e"]]