지명은 USGS 지명위원회(USGS Board on Geographic Names), 미국 지명정보 시스템(U.S. Gazetteer Files)과 같은 여러 소스에서 제공합니다.
PlaceFeature를 사용하여 장소 ID 가져오기
PlaceFeature 클래스는 Feature 클래스의 서브클래스입니다.
ADMINISTRATIVE_AREA_LEVEL_1, ADMINISTRATIVE_AREA_LEVEL_2, COUNTRY, LOCALITY, POSTAL_CODE, SCHOOL_DISTRICT 유형의 기능을 포함하는 장소 기능 (장소 ID가 있는 기능)을 나타냅니다.
장소 ID를 사용할 수 있는 경우 Android용 지도 SDK는 기능의 위치를 확인할 수 있도록 PlaceFeature 인스턴스를 스타일 팩토리 함수에 전달합니다.
스타일 팩토리 예
이 예에서는 지역 지형지물 레이어의 다각형에 스타일 팩토리 함수를 적용합니다. 스타일 팩토리 함수는 PlaceFeature 인스턴스를 사용하여 지형지물의 장소 ID를 확인합니다. 장소 ID가 하와이 하나인 경우 함수는 맞춤 채우기 및 획 스타일을 다각형에 적용합니다.
새 지도 ID와 지도 스타일을 아직 만들지 않았다면 시작하기의 단계에 따라 만드세요. 지역 지형지물 레이어를 사용 설정해야 합니다.
지도가 초기화될 때 지역 지형지물 레이어에 대한 참조를 가져옵니다.
자바
privateFeatureLayerlocalityLayer; @OverridepublicvoidonMapReady(GoogleMapmap){// Get the LOCALITY feature layer.localityLayer=map.getFeatureLayer(newFeatureLayerOptions.Builder().featureType(FeatureType.LOCALITY).build()); // Apply style factory function to LOCALITY layer.styleLocalityLayer();}
Kotlin
privatevarlocalityLayer:FeatureLayer?=null overridefunonMapReady(googleMap:GoogleMap){// Get the LOCALITY feature layer.localityLayer=googleMap.getFeatureLayer(FeatureLayerOptions.Builder().featureType(FeatureType.LOCALITY).build()) // Apply style factory function to LOCALITY layer.styleLocalityLayer()}
스타일 팩토리 함수를 만들고 Locality 지형지물 레이어에 적용합니다.
다음 예에서는 피처의 장소 ID가 하와이 하나 ('ChIJ0zQtYiWsVHkRk8lRoB1RNPo')인 경우에만 함수를 적용합니다.
지정된 장소 ID가 하와이 하나가 아닌 경우 스타일이 적용되지 않습니다.
자바
privatevoidstyleLocalityLayer(){ // Create the style factory function.FeatureLayer.StyleFactorystyleFactory=(Featurefeature)->{ // Check if the feature is an instance of PlaceFeature,// which contains a place ID.if(featureinstanceofPlaceFeature){PlaceFeatureplaceFeature=(PlaceFeature)feature; // Determine if the place ID is for Hana, HI.if(placeFeature.getPlaceId().equals("ChIJ0zQtYiWsVHkRk8lRoB1RNPo")){ // Use FeatureStyle.Builder to configure the FeatureStyle object// returned by the style factory function.returnnewFeatureStyle.Builder()// Define a style with purple fill at 50% opacity and solid purple border..fillColor(0x80810FCB).strokeColor(0xFF810FCB).build();}}returnnull;}; // Apply the style factory function to the feature layer.localityLayer.setFeatureStyle(styleFactory);}
Kotlin
privatefunstyleLocalityLayer(){ // Create the style factory function.valstyleFactory=FeatureLayer.StyleFactory{feature:Feature-> // Check if the feature is an instance of PlaceFeature,// which contains a place ID.if(featureisPlaceFeature){valplaceFeature:PlaceFeature=featureasPlaceFeature // Determine if the place ID is for Hana, HI.if(placeFeature.getPlaceId().equals("ChIJ0zQtYiWsVHkRk8lRoB1RNPo")){ // Use FeatureStyle.Builder to configure the FeatureStyle object// returned by the style factory function.return@StyleFactoryFeatureStyle.Builder()// Define a style with purple fill at 50% opacity and// solid purple border..fillColor(0x80810FCB.toInt()).strokeColor(0xFF810FCB.toInt()).build()}}return@StyleFactorynull} // Apply the style factory function to the feature layer.localityLayer?.setFeatureStyle(styleFactory)}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-16(UTC)"],[[["\u003cp\u003eDefine a style factory function that implements the \u003ccode\u003eFeatureLayer.StyleFactory\u003c/code\u003e interface to control the styling logic for boundary polygons in a feature layer.\u003c/p\u003e\n"],["\u003cp\u003eApply the style factory to the feature layer using \u003ccode\u003eFeatureLayer.setFeatureStyle()\u003c/code\u003e, customizing stroke and fill colors for polygon borders and interiors.\u003c/p\u003e\n"],["\u003cp\u003eUtilize place IDs to target specific features for styling, retrieving them through Places APIs, Geocoding, or click events.\u003c/p\u003e\n"],["\u003cp\u003eAccess the place ID of a feature using the \u003ccode\u003ePlaceFeature\u003c/code\u003e class within the style factory function to apply location-based styles.\u003c/p\u003e\n"],["\u003cp\u003eRemove styling from a layer by calling \u003ccode\u003eFeatureLayer.setFeatureStyle(null)\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-boundaries/style-polygon \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-boundaries/style-polygon \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-boundaries/style-polygon \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nTo apply styles for stroke and fill to boundary polygons in a feature layer:\n\n1. Create a style factory function that implements the\n [`FeatureLayer.StyleFactory`](/android/reference/com/google/android/gms/maps/model/FeatureLayer.StyleFactory)\n interface. This function defines the styling logic for a feature layer.\n\n2. Call\n [`FeatureLayer.setFeatureStyle()`](/android/reference/com/google/android/gms/maps/model/FeatureLayer#setFeatureStyle(com.google.android.gms.maps.model.FeatureLayer.StyleFactory))\n to apply the style factory function to the feature layer.\n\nThe following example map demonstrates highlighting the boundary polygon for a\nsingle region in a Locality feature layer.\n\nCreate a style factory function\n\nThe style factory function is applied to every polygon in the affected feature\nlayer at the time you set the function on the feature layer. This function must\nreturn a [`FeatureStyle`](/android/reference/com/google/android/gms/maps/model/FeatureStyle)\nobject that specifies how to style the polygon.\n| **Note:** If you update or modify the style factory function for a feature layer, you must call `FeatureLayer.setFeatureStyle()` again to reset the function on the feature layer.\n\nMaps SDK for Android passes a\n[`Feature`](/android/reference/com/google/android/gms/maps/model/Feature)\ninstance to the style factory function. The `Feature` instance represents the\nfeature's metadata, giving you access to the metadata in the style factory\nfunction.\n\nThe style factory function should always return consistent results when it is\napplied. For example, if you wanted to randomly color a set of features, the\nrandom part shouldn't take place in the feature style function, as that would\ncause unintended results.\n\nBecause this function runs over every feature in a layer, optimization is\nimportant. To avoid impacting rendering times:\n\n- Enable only the feature layers you need.\n\n- Call `FeatureLayer.setFeatureStyle(null)` when a feature layer is no longer\n in use.\n\nSet polygon stroke and fill\n\nWhen styling a boundary polygon in the style factory function, you can set the:\n\n- **Stroke color and opacity** of the polygon border in the ARGB color format,\n as defined by the\n [`Color`](https://developer.android.com/reference/android/graphics/Color.html)\n class. The default value is transparent (0x00000000).\n\n- **Stroke width** of the polygon border in screen pixels. The default value\n is 2.\n\n- **Fill color and opacity** of the polygon in the ARGB color format, as\n defined by the\n [`Color`](https://developer.android.com/reference/android/graphics/Color.html)\n class. The default value is transparent (0x00000000).\n\nLookup place IDs to target features\n\nMany applications apply styles to a feature based on the feature location. For\nexample, you might want to apply styling to different countries, territories, or\nregions. The feature location is represented by a\n[place ID](/maps/documentation/places/android-sdk/place-id).\n\nPlace IDs uniquely identify a place in the Google Places database and on Google\nMaps. To get a place ID:\n\n- [Use Places APIs and Geocoding](/maps/documentation/android-sdk/dds-boundaries/dds-use-maps-places-apis) to search for regions by name, and get place IDs for regions within specified bounds.\n- [Get data from click events](/maps/documentation/android-sdk/dds-boundaries/handle-events). This returns the Feature corresponding to a region clicked, which provides access to its place ID and feature type category.\n\nCoverage varies by region. See\n[Google boundaries coverage](/maps/documentation/android-sdk/dds-boundaries/coverage)\nfor details.\n\nGeographic names are available from many sources, such as the\n[USGS Board on Geographic Names](https://edits.nationalmap.gov/apps/gaz-domestic/public/search/names),\nand the\n[U.S. Gazetteer Files](https://www.census.gov/geographies/reference-files/time-series/geo/gazetteer-files.html).\n\nUse PlaceFeature to get a place ID\n\nThe [`PlaceFeature`](/android/reference/com/google/android/gms/maps/model/PlaceFeature)\nclass is a subclass of the `Feature` class.\nIt represents a *place feature* (a feature with a place ID) which includes\nfeatures of type `ADMINISTRATIVE_AREA_LEVEL_1`, `ADMINISTRATIVE_AREA_LEVEL_2`,\n`COUNTRY`, `LOCALITY`, `POSTAL_CODE`, and `SCHOOL_DISTRICT`.\n\nWhen the place ID is available, the\nMaps SDK for Android passes an instance of `PlaceFeature` to the style factory\nfunction so that you can determine the location of the feature.\n\nStyle factory example\n\nThis example applies a style factory function to a polygon in the Locality\nfeature layer. The style factory function determines the place ID of the feature\nby using the `PlaceFeature` instance. If the place ID is for Hana, Hawaii then\nthe function applies a custom fill and stroke style to the polygon:\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 **Locality**\n feature layer.\n\n2. Get a reference to the Locality feature layer when the map initializes.\n\n Java\n\n\n ```java\n private FeatureLayer localityLayer;\n\n @Override\n public void onMapReady(GoogleMap map) {\n // Get the LOCALITY feature layer.\n localityLayer = map.getFeatureLayer(new FeatureLayerOptions.Builder()\n .featureType(FeatureType.LOCALITY)\n .build());\n\n // Apply style factory function to LOCALITY layer.\n styleLocalityLayer();\n }\n ```\n\n \u003cbr /\u003e\n\n Kotlin\n\n\n ```java\n private var localityLayer: FeatureLayer? = null\n\n override fun onMapReady(googleMap: GoogleMap) {\n // Get the LOCALITY feature layer.\n localityLayer = googleMap.getFeatureLayer(FeatureLayerOptions.Builder()\n .featureType(FeatureType.LOCALITY)\n .build())\n\n // Apply style factory function to LOCALITY layer.\n styleLocalityLayer()\n }\n ```\n\n \u003cbr /\u003e\n\n3. Create a style factory function and apply it to the Locality\n feature layer.\n\n The following example only applies the function if the place\n ID of the feature is for Hana, Hawaii (\"ChIJ0zQtYiWsVHkRk8lRoB1RNPo\").\n If the specified place ID is not for Hana, Hawaii then the style is not\n applied. \n\n Java\n\n\n ```java\n private void styleLocalityLayer() {\n\n // Create the style factory function.\n FeatureLayer.StyleFactory styleFactory = (Feature feature) -\u003e {\n\n // Check if the feature is an instance of PlaceFeature,\n // which contains a place ID.\n if (feature instanceof PlaceFeature) {\n PlaceFeature placeFeature = (PlaceFeature) feature;\n\n // Determine if the place ID is for Hana, HI.\n if (placeFeature.getPlaceId().equals(\"ChIJ0zQtYiWsVHkRk8lRoB1RNPo\")) {\n\n // Use FeatureStyle.Builder to configure the FeatureStyle object\n // returned by the style factory function.\n return new FeatureStyle.Builder()\n // Define a style with purple fill at 50% opacity and solid purple border.\n .fillColor(0x80810FCB)\n .strokeColor(0xFF810FCB)\n .build();\n }\n }\n return null;\n };\n\n // Apply the style factory function to the feature layer.\n localityLayer.setFeatureStyle(styleFactory);\n }\n ```\n\n \u003cbr /\u003e\n\n Kotlin\n\n\n ```java\n private fun styleLocalityLayer() {\n\n // Create the style factory function.\n val styleFactory = FeatureLayer.StyleFactory { feature: Feature -\u003e\n\n // Check if the feature is an instance of PlaceFeature,\n // which contains a place ID.\n if (feature is PlaceFeature) {\n val placeFeature: PlaceFeature = feature as PlaceFeature\n\n // Determine if the place ID is for Hana, HI.\n if (placeFeature.getPlaceId().equals(\"ChIJ0zQtYiWsVHkRk8lRoB1RNPo\")) {\n\n // Use FeatureStyle.Builder to configure the FeatureStyle object\n // returned by the style factory function.\n return@StyleFactory FeatureStyle.Builder()\n // Define a style with purple fill at 50% opacity and\n // solid purple border.\n .fillColor(0x80810FCB.toInt())\n .strokeColor(0xFF810FCB.toInt())\n .build()\n }\n }\n return@StyleFactory null\n }\n\n // Apply the style factory function to the feature layer.\n localityLayer?.setFeatureStyle(styleFactory)\n }\n ```\n\n \u003cbr /\u003e\n\nRemove styling from a layer\n\nTo remove styling from a layer, call `FeatureLayer.setFeatureStyle(null)`."]]