Eine Choroplethenkarte (Intensitätskarte) ist eine thematische Karte, bei der Verwaltungsgebiete gemäß einem Datenwert eingefärbt bzw. schattiert werden. Mit einer Style-Factory-Funktion können Sie den Stil einer Karte basierend auf Daten definieren, wobei jedem Verwaltungsbereich ein numerischer Wertebereich zugeordnet ist. Die folgende Beispielkarte zeigt eine Choroplethenkarte für die Bundesstaaten der USA.
In diesem Beispiel bestehen die Daten aus der Orts-ID des Bundesstaates. Mit der Style-Factory-Funktion wird jede Region basierend auf einem gehashten Wert der Orts-ID für die Region bedingt eingefärbt.
Falls noch nicht geschehen, erstellen Sie eine neue Karten-ID und einen neuen Kartenstil. Folgen Sie dazu der Anleitung unter Erste Schritte. Aktivieren Sie auf jeden Fall die Element-Ebene Verwaltungsgebiet Ebene 1.
Rufen Sie einen Verweis auf die Elementebene „Verwaltungsgebiet 1. Ebene“ ab, wenn die Karte initialisiert wird. In den USA entsprechen diese Verwaltungsebenen den einzelnen Bundesstaaten.
Java
privateFeatureLayerareaLevel1Layer; @OverridepublicvoidonMapReady(GoogleMapmap){areaLevel1Layer=map.getFeatureLayer(newFeatureLayerOptions.Builder().featureType(FeatureType.ADMINISTRATIVE_AREA_LEVEL_1).build()); // Apply style factory function to ADMINISTRATIVE_AREA_LEVEL_1 layer.styleAreaLevel1Layer();}
Kotlin
privatevarareaLevel1Layer:FeatureLayer?=null overridefunonMapReady(googleMap:GoogleMap){// Get the ADMINISTRATIVE_AREA_LEVEL_1 feature layer.areaLevel1Layer=googleMap.getFeatureLayer(FeatureLayerOptions.Builder().featureType(FeatureType.ADMINISTRATIVE_AREA_LEVEL_1).build()) // Apply style factory function to ADMINISTRATIVE_AREA_LEVEL_1 layer.styleAreaLevel1Layer()}
Erstellen Sie eine Stil-Factory-Funktion und wenden Sie sie auf die Elementebene „Administrative Area Level 1“ an. Im folgenden Beispiel wird die Funktion auf das Polygon angewendet, das jeden Bundesstaat der USA darstellt.
Java
privatevoidstyleAreaLevel1Layer(){FeatureLayer.StyleFactorystyleFactory=(Featurefeature)->{if(featureinstanceofPlaceFeature){PlaceFeatureplaceFeature=(PlaceFeature)feature; // Return a hueColor in the range [-299,299]. If the value is// negative, add 300 to make the value positive.inthueColor=placeFeature.getPlaceId().hashCode()%300;if(hueColor < 0){hueColor+=300;} returnnewFeatureStyle.Builder()// Set the fill color for the state based on the hashed hue color..fillColor(Color.HSVToColor(150,newfloat[]{hueColor,1,1})).build();}returnnull;}; // Apply the style factory function to the feature layer.areaLevel1Layer.setFeatureStyle(styleFactory);}
Kotlin
privatefunstyleAreaLevel1Layer(){valstyleFactory=FeatureLayer.StyleFactory{feature:Feature->
if(featureisPlaceFeature){valplaceFeature:PlaceFeature=featureasPlaceFeature // Return a hueColor in the range [-299,299]. If the value is// negative, add 300 to make the value positive.varhueColor:Int=placeFeature.getPlaceId().hashCode()%300if(hueColor < 0){hueColor+=300}return@StyleFactoryFeatureStyle.Builder()// Set the fill color for the state based on the hashed hue color..fillColor(Color.HSVToColor(150,floatArrayOf(hueColor.toFloat(),1f,1f))).build()}return@StyleFactorynull} // Apply the style factory function to the feature layer.areaLevel1Layer?.setFeatureStyle(styleFactory)}
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-16 (UTC)."],[[["\u003cp\u003eChoropleth maps use color variations to represent data values associated with geographic areas, like shading states based on population.\u003c/p\u003e\n"],["\u003cp\u003eThis guide explains how to create a choropleth map using a style factory function that colors administrative areas based on data ranges.\u003c/p\u003e\n"],["\u003cp\u003eYou'll learn to enable the "Administrative Area Level 1" feature, access this layer, and apply a style factory function to it, demonstrated with code snippets for Android (Java/Kotlin).\u003c/p\u003e\n"],["\u003cp\u003eThe example provided utilizes a hashed value of the place ID to determine the color of each state, although real-world scenarios would likely involve a lookup table for color assignments.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-boundaries/choropleth-map \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-boundaries/choropleth-map \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-boundaries/choropleth-map \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nA choropleth map is a type of thematic map in which administrative areas are\ncolored or shaded according to a data value. You can use a style factory\nfunction to style a map based on data where each administrative area is\nassociated with a range of numeric values. The following example map shows a\nchoropleth map for the states of the United States.\n\nIn this example, the data consists of the place ID of the state. The style\nfactory function conditionally colors each state based on a hashed value of the\nplace ID for the state.\n\n| **Note:** Typically, you would define a table of the color for each state, and then lookup the color for each state based on the state's place ID.\n\n1. If you haven't already done so, follow the steps in\n [Get Started](/maps/documentation/android/dds-boundaries/start)\n to create a new map ID and map style. Be sure to enable the\n **Administrative Area Level 1** feature layer.\n\n2. Get a reference to the Administrative Area Level 1 feature layer when the\n map initializes. For the United States, these administrative levels\n correspond to the individual states.\n\n Java\n\n\n ```java\n private FeatureLayer areaLevel1Layer;\n\n @Override\n public void onMapReady(GoogleMap map) {\n areaLevel1Layer = map.getFeatureLayer(new FeatureLayerOptions.Builder()\n .featureType(FeatureType.ADMINISTRATIVE_AREA_LEVEL_1)\n .build());\n\n // Apply style factory function to ADMINISTRATIVE_AREA_LEVEL_1 layer.\n styleAreaLevel1Layer();\n }\n ```\n\n \u003cbr /\u003e\n\n Kotlin\n\n\n ```java\n private var areaLevel1Layer: FeatureLayer? = null\n\n override fun onMapReady(googleMap: GoogleMap) {\n // Get the ADMINISTRATIVE_AREA_LEVEL_1 feature layer.\n areaLevel1Layer = googleMap.getFeatureLayer(FeatureLayerOptions.Builder()\n .featureType(FeatureType.ADMINISTRATIVE_AREA_LEVEL_1)\n .build())\n\n // Apply style factory function to ADMINISTRATIVE_AREA_LEVEL_1 layer.\n styleAreaLevel1Layer()\n }\n ```\n\n \u003cbr /\u003e\n\n3. Create a style factory function and apply it to the\n Administrative Area Level 1 feature layer. The following example applies the\n function to the polygon representing each state of the United States.\n\n Java\n\n\n ```java\n private void styleAreaLevel1Layer() {\n FeatureLayer.StyleFactory styleFactory = (Feature feature) -\u003e {\n if (feature instanceof PlaceFeature) {\n PlaceFeature placeFeature = (PlaceFeature) feature;\n\n // Return a hueColor in the range [-299,299]. If the value is\n // negative, add 300 to make the value positive.\n int hueColor = placeFeature.getPlaceId().hashCode() % 300;\n if (hueColor \u003c 0) {\n hueColor += 300;\n }\n\n return new FeatureStyle.Builder()\n // Set the fill color for the state based on the hashed hue color.\n .fillColor(Color.HSVToColor(150, new float[] {hueColor, 1, 1}))\n .build();\n }\n return null;\n };\n\n // Apply the style factory function to the feature layer.\n areaLevel1Layer.setFeatureStyle(styleFactory);\n }\n ```\n\n \u003cbr /\u003e\n\n Kotlin\n\n\n ```java\n private fun styleAreaLevel1Layer() {\n val styleFactory = FeatureLayer.StyleFactory { feature: Feature -\u003e\n if (feature is PlaceFeature) {\n val placeFeature: PlaceFeature = feature as PlaceFeature\n\n // Return a hueColor in the range [-299,299]. If the value is\n // negative, add 300 to make the value positive.\n var hueColor: Int = placeFeature.getPlaceId().hashCode() % 300\n if (hueColor \u003c 0) {\n hueColor += 300\n }\n return@StyleFactory FeatureStyle.Builder()\n // Set the fill color for the state based on the hashed hue color.\n .fillColor(Color.HSVToColor(150, floatArrayOf(hueColor.toFloat(), 1f, 1f)))\n .build()\n }\n return@StyleFactory null\n }\n\n // Apply the style factory function to the feature layer.\n areaLevel1Layer?.setFeatureStyle(styleFactory)\n }\n ```\n\n \u003cbr /\u003e"]]