Une carte choroplèthe est un type de carte thématique dans laquelle les régions administratives sont colorées ou nuancées en fonction d'une valeur de données. Vous pouvez utiliser GMSFeatureLayer pour styliser une carte en fonction de données où chaque région administrative est associée à une plage de valeurs numériques.
Dans cet exemple, les données sont constituées d'un tableau de paires clé/valeur, correspondant au nom à afficher de chaque État avec une valeur numérique de population.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/31 (UTC).
[null,null,["Dernière mise à jour le 2025/08/31 (UTC)."],[[["\u003cp\u003eChoropleth maps display administrative areas colored based on data values, like population.\u003c/p\u003e\n"],["\u003cp\u003eYou can create choropleth maps using \u003ccode\u003eGMSFeatureLayer\u003c/code\u003e by associating areas with numeric ranges.\u003c/p\u003e\n"],["\u003cp\u003eThis example uses state population data to color states with varying hues based on population density.\u003c/p\u003e\n"],["\u003cp\u003eStyling Places data might require using the Places SDK for iOS, although not always necessary.\u003c/p\u003e\n"]]],["This content describes creating a choropleth map using `GMSFeatureLayer`, where administrative areas are styled based on associated data. Key actions include defining a data set as key-value pairs, mapping state display names to numeric values like population. The `featureLayer.style` is used to assign color styles to each area based on its numeric data. The example code in Swift and Objective-C shows how to apply the color scheme with `UIColor` based on data value ranges to a `GMSPlaceFeature`.\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\n[`GMSFeatureLayer`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSFeatureLayer) to style a map based on data where\neach administrative area is associated with a range of numeric values.\n\nIn this example, the data consists of an array of key-value pairs, matching the\ndisplay name of each state with a numeric population value.\n**Important:** While not required for all capabilities, styling of Places data may require integration with the [Places SDK for iOS](/maps/documentation/places/ios-sdk). \n\nSwift \n\n```swift\n//..\n\nlet featureLayer = mapView.featureLayer(of: FeatureType.administrativeAreaLevel1)\n\nlet populationOfStates = [\n\"ChIJdf5LHzR_hogR6czIUzU0VV4\": 5_039_877,\n\"ChIJG8CuwJzfAFQRNduKqSde27w\": 732673,\n\"ChIJaxhMy-sIK4cRcc3Bf7EnOUI\": 7_276_316,\n\"ChIJYSc_dD-e0ocR0NLf_z5pBaQ\": 3_025_891,\n\"ChIJPV4oX_65j4ARVW8IJ6IJUYs\": 39_237_836, // California\n\"ChIJt1YYm3QUQIcR_6eQSTGDVMc\": 5_812_069,\n\"ChIJpVER8hFT5okR5XBhBVttmq4\": 3_605_597,\n\"ChIJO9YMTXYFx4kReOgEjBItHZQ\": 1_003_384,\n\"ChIJvypWkWV2wYgR0E7HW9MTLvc\": 21_781_128,\n\"ChIJV4FfHcU28YgR5xBP7BC8hGY\": 10_799_566,\n\"ChIJBeB5Twbb_3sRKIbMdNKCd0s\": 1_441_553,\n\"ChIJ6Znkhaj_WFMRWIf3FQUwa9A\": 1_900_923,\n\"ChIJGSZubzgtC4gRVlkRZFCCFX8\": 12_671_469,\n\"ChIJHRv42bxQa4gRcuwyy84vEH4\": 6_805_985,\n\"ChIJGWD48W9e7ocR2VnHV0pj78Y\": 3_193_079,\n\"ChIJawF8cXEXo4cRXwk-S6m0wmg\": 2_934_582,\n\"ChIJyVMZi0xzQogR_N_MxU5vH3c\": 4_509_394,\n\"ChIJZYIRslSkIIYRA0flgTL3Vck\": 4_624_047,\n\"ChIJ1YpTHd4dsEwR0KggZ2_MedY\": 1_372_247,\n\"ChIJ35Dx6etNtokRsfZVdmU3r_I\": 6_165_129,\n\"ChIJ_b9z6W1l44kRHA2DVTbQxkU\": 6_984_723,\n\"ChIJEQTKxz2qTE0Rs8liellI3Zc\": 10_050_811,\n\"ChIJmwt4YJpbWE0RD6L-EJvJogI\": 5_707_390,\n\"ChIJGdRK5OQyKIYR2qbc6X8XDWI\": 2_949_965,\n\"ChIJfeMiSNXmwIcRcr1mBFnEW7U\": 6_168_187,\n\"ChIJ04p7LZwrQVMRGGwqz1jWcfU\": 1_104_271,\n\"ChIJ7fwMtciNk4cRxArzDwyQJ6E\": 1_963_692,\n\"ChIJcbTe-KEKmYARs5X8qooDR88\": 3_143_991,\n\"ChIJ66bAnUtEs0wR64CmJa8CyNc\": 1_388_992,\n\"ChIJn0AAnpX7wIkRjW0_-Ad70iw\": 9_267_130,\n\"ChIJqVKY50NQGIcRup41Yxpuv0Y\": 2_115_877,\n\"ChIJqaUj8fBLzEwRZ5UY3sHGz90\": 19_835_913,\n\"ChIJgRo4_MQfVIgRGa4i6fUwP60\": 10_551_162,\n\"ChIJY-nYVxKD11IRyc9egzmahA0\": 774948,\n\"ChIJwY5NtXrpNogRFtmfnDlkzeU\": 11_780_017,\n\"ChIJnU-ssRE5rIcRSOoKQDPPHF0\": 3_986_639,\n\"ChIJVWqfm3xuk1QRdrgLettlTH0\": 4_246_155,\n\"ChIJieUyHiaALYgRPbQiUEchRsI\": 12_964_056,\n\"ChIJD9cOYhQ15IkR5wbB57wYTh4\": 1_095_610,\n\"ChIJ49ExeWml-IgRnhcF9TKh_7k\": 5_190_705,\n\"ChIJpTjphS1DfYcRt6SGMSnW8Ac\": 895376,\n\"ChIJA8-XniNLYYgRVpGBpcEgPgM\": 6_975_218,\n\"ChIJSTKCCzZwQIYRPN4IGI8c6xY\": 29_527_941,\n\"ChIJzfkTj8drTIcRP0bXbKVK370\": 3_337_975,\n\"ChIJ_87aSGzctEwRtGtUNnSJTSY\": 645570,\n\"ChIJzbK8vXDWTIgRlaZGt0lBTsA\": 8_642_274,\n\"ChIJ-bDD5__lhVQRuvNfbGh4QpQ\": 7_738_692,\n\"ChIJRQnL1KVUSogRQzrN3mjHALs\": 1_782_959,\n\"ChIJr-OEkw_0qFIR1kmG-LjV1fI\": 5_895_908,\n\"ChIJaS7hSDTiXocRLzh90nkisCY\": 578803, // Wyoming\n]\n\nfeatureLayer.style = { feature in\n FeatureStyle(\n fill: populationOfStates[feature.placeID].map {\n UIColor(\n hue: log(CGFloat($0) / 5e5) / 7.5,\n saturation: 1,\n brightness: 0.75,\n alpha: 0.5)\n } ?? nil,\n stroke: nil,\n strokeWidth: 0\n )\n}\n\nself.view = mapView\n```\n\nObjective-C \n\n```objective-c\n//..\n\nGMSFeatureLayer\u003cGMSPlaceFeature *\u003e *featureLayer =\n [mapView featureLayerOfFeatureType:GMSFeatureTypeAdministrativeAreaLevel1];\n\nNSDictionary\u003cNSString *, NSNumber *\u003e *populationOfStates = @{\n @\"ChIJdf5LHzR_hogR6czIUzU0VV4\" : @(5039877),\n @\"ChIJG8CuwJzfAFQRNduKqSde27w\" : @(732673),\n @\"ChIJaxhMy-sIK4cRcc3Bf7EnOUI\" : @(7276316),\n @\"ChIJYSc_dD-e0ocR0NLf_z5pBaQ\" : @(3025891),\n @\"ChIJPV4oX_65j4ARVW8IJ6IJUYs\" : @(39237836), // California\n @\"ChIJt1YYm3QUQIcR_6eQSTGDVMc\" : @(5812069),\n @\"ChIJpVER8hFT5okR5XBhBVttmq4\" : @(3605597),\n @\"ChIJO9YMTXYFx4kReOgEjBItHZQ\" : @(1003384),\n @\"ChIJvypWkWV2wYgR0E7HW9MTLvc\" : @(21781128),\n @\"ChIJV4FfHcU28YgR5xBP7BC8hGY\" : @(10799566),\n @\"ChIJBeB5Twbb_3sRKIbMdNKCd0s\" : @(1441553),\n @\"ChIJ6Znkhaj_WFMRWIf3FQUwa9A\" : @(1900923),\n @\"ChIJGSZubzgtC4gRVlkRZFCCFX8\" : @(12671469),\n @\"ChIJHRv42bxQa4gRcuwyy84vEH4\" : @(6805985),\n @\"ChIJGWD48W9e7ocR2VnHV0pj78Y\" : @(3193079),\n @\"ChIJawF8cXEXo4cRXwk-S6m0wmg\" : @(2934582),\n @\"ChIJyVMZi0xzQogR_N_MxU5vH3c\" : @(4509394),\n @\"ChIJZYIRslSkIIYRA0flgTL3Vck\" : @(4624047),\n @\"ChIJ1YpTHd4dsEwR0KggZ2_MedY\" : @(1372247),\n @\"ChIJ35Dx6etNtokRsfZVdmU3r_I\" : @(6165129),\n @\"ChIJ_b9z6W1l44kRHA2DVTbQxkU\" : @(6984723),\n @\"ChIJEQTKxz2qTE0Rs8liellI3Zc\" : @(10050811),\n @\"ChIJmwt4YJpbWE0RD6L-EJvJogI\" : @(5707390),\n @\"ChIJGdRK5OQyKIYR2qbc6X8XDWI\" : @(2949965),\n @\"ChIJfeMiSNXmwIcRcr1mBFnEW7U\" : @(6168187),\n @\"ChIJ04p7LZwrQVMRGGwqz1jWcfU\" : @(1104271),\n @\"ChIJ7fwMtciNk4cRxArzDwyQJ6E\" : @(1963692),\n @\"ChIJcbTe-KEKmYARs5X8qooDR88\" : @(3143991),\n @\"ChIJ66bAnUtEs0wR64CmJa8CyNc\" : @(1388992),\n @\"ChIJn0AAnpX7wIkRjW0_-Ad70iw\" : @(9267130),\n @\"ChIJqVKY50NQGIcRup41Yxpuv0Y\" : @(2115877),\n @\"ChIJqaUj8fBLzEwRZ5UY3sHGz90\" : @(19835913),\n @\"ChIJgRo4_MQfVIgRGa4i6fUwP60\" : @(10551162),\n @\"ChIJY-nYVxKD11IRyc9egzmahA0\" : @(774948),\n @\"ChIJwY5NtXrpNogRFtmfnDlkzeU\" : @(11780017),\n @\"ChIJnU-ssRE5rIcRSOoKQDPPHF0\" : @(3986639),\n @\"ChIJVWqfm3xuk1QRdrgLettlTH0\" : @(4246155),\n @\"ChIJieUyHiaALYgRPbQiUEchRsI\" : @(12964056),\n @\"ChIJD9cOYhQ15IkR5wbB57wYTh4\" : @(1095610),\n @\"ChIJ49ExeWml-IgRnhcF9TKh_7k\" : @(5190705),\n @\"ChIJpTjphS1DfYcRt6SGMSnW8Ac\" : @(895376),\n @\"ChIJA8-XniNLYYgRVpGBpcEgPgM\" : @(6975218),\n @\"ChIJSTKCCzZwQIYRPN4IGI8c6xY\" : @(29527941),\n @\"ChIJzfkTj8drTIcRP0bXbKVK370\" : @(3337975),\n @\"ChIJ_87aSGzctEwRtGtUNnSJTSY\" : @(645570),\n @\"ChIJzbK8vXDWTIgRlaZGt0lBTsA\" : @(8642274),\n @\"ChIJ-bDD5__lhVQRuvNfbGh4QpQ\" : @(7738692),\n @\"ChIJRQnL1KVUSogRQzrN3mjHALs\" : @(1782959),\n @\"ChIJr-OEkw_0qFIR1kmG-LjV1fI\" : @(5895908),\n @\"ChIJaS7hSDTiXocRLzh90nkisCY\" : @(578803), // Wyoming\n};\n\nfeatureLayer.style = ^(GMSPlaceFeature *feature) {\n NSNumber *population = populationOfStates[feature.placeID];\n UIColor *fillColor = population ? [UIColor colorWithHue:(log(population.doubleValue / 5e5) / 7.5) saturation:1 brightness:0.5 alpha:0.5] : nil;\n return [GMSFeatureStyle styleWithFillColor:fillColor strokeColor:nil strokeWidth:0.0];\n};\n\nself.view = mapView;\n```"]]