private val SYDNEY = LatLng(-33.87365, 151.20689)
val marker: Marker? = map.addMarker(
AdvancedMarkerOptions()
.position(SYDNEY)
.iconView(textView)
.zIndex(zIndex)
)
Java
private final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
Marker marker = map.addMarker(
new AdvancedMarkerOptions()
.position(SYDNEY)
.iconView(textView)
.zIndex(zIndex));
GoogleMap.addMarker()는 Marker 인스턴스를 반환합니다.
필요한 경우 반환된 값을 AdvancedMarker로 변환할 수 있습니다.
AdvancedMarkerOptions로 고급 마커를 구성하세요.
AdvancedMarkerOptions는 MarkerOptions의 서브클래스이므로 MarkerOptions에서 지원되는 모든 설정을 지원합니다.
AdvancedMarkerOptions로 다음 작업도 가능합니다.
PinConfig 클래스의 인스턴스를 하나 만들고 PinConfig 인스턴스로 AdvancedMarkerOptions 인스턴스를 구성합니다.
PinConfig로 배경 색상, 테두리 색상, 글리프와 같은 고급 마커 속성을 맞춤설정합니다.
Android View 클래스의 인스턴스를 하나 만들고 해당 인스턴스로 AdvancedMarkerOptions 인스턴스를 구성합니다.
View 인스턴스로 마커를 완전히 맞춤설정할 수 있습니다.
PinConfig 사용
PinConfig 클래스에는 고급 마커를 맞춤설정하는 옵션이 포함되어 있습니다. PinConfig로 다음 작업을 할 수 있습니다.
// Use PinConfig.Builder to create an instance of PinConfig.
val pinConfigBuilder: PinConfig.Builder = PinConfig.builder()
pinConfigBuilder.setBackgroundColor(Color.MAGENTA)
val pinConfig: PinConfig = pinConfigBuilder.build()
// Use the PinConfig instance to set the icon for AdvancedMarkerOptions.
val advancedMarkerOptions: AdvancedMarkerOptions = AdvancedMarkerOptions()
.icon(BitmapDescriptorFactory.fromPinConfig(pinConfig))
.position(MARKER_POSITION)
// Pass the AdvancedMarkerOptions instance to addMarker().
val marker: Marker? = map.addMarker(advancedMarkerOptions)
Java
// Use PinConfig.Builder to create an instance of PinConfig.
PinConfig.Builder pinConfigBuilder = PinConfig.builder();
pinConfigBuilder.setBackgroundColor(Color.MAGENTA);
PinConfig pinConfig = pinConfigBuilder.build();
// Use the PinConfig instance to set the icon for AdvancedMarkerOptions.
AdvancedMarkerOptions advancedMarkerOptions =
new AdvancedMarkerOptions()
.icon(BitmapDescriptorFactory.fromPinConfig(pinConfig))
.position(MARKER_POSITION);
// Pass the AdvancedMarkerOptions instance to addMarker().
Marker marker = map.addMarker(advancedMarkerOptions);
배경 색상 변경
마커의 배경 색상을 변경하려면 PinConfig.background() 메서드를 사용합니다.
Kotlin
// Use PinConfig.Builder to create an instance of PinConfig.
val pinConfigBuilder: PinConfig.Builder = PinConfig.builder()
pinConfigBuilder.setBackgroundColor(Color.MAGENTA)
val pinConfig: PinConfig = pinConfigBuilder.build()
Java
// Use PinConfig.Builder to create an instance of PinConfig.
PinConfig.Builder pinConfigBuilder = PinConfig.builder();
pinConfigBuilder.setBackgroundColor(Color.MAGENTA);
PinConfig pinConfig = pinConfigBuilder.build();
// Set the border color.
val pinConfigBuilder: PinConfig.Builder = PinConfig.builder()
pinConfigBuilder.setBorderColor(Color.BLUE)
val pinConfig: PinConfig = pinConfigBuilder.build()
Java
// Set the border color.
PinConfig.Builder pinConfigBuilder = PinConfig.builder();
pinConfigBuilder.setBorderColor(Color.BLUE);
PinConfig pinConfig = pinConfigBuilder.build();
글리프 변경
Glyph 인스턴스를 만들고 해당 인스턴스로 PinConfig를 구성합니다.
글리프를 통해 글리프 텍스트, 텍스트 색상 및 글리프 색상을 설정하거나 글리프로 사용할 맞춤 이미지를 지정합니다.
다음 예에서는 글리프 텍스트를 설정합니다.
Kotlin
// Set the glyph text.
val pinConfigBuilder: PinConfig.Builder = PinConfig.builder()
val glyphText = Glyph("A")
// Alteratively, you can set the text color:
// Glyph glyphText = new Glyph("A", Color.GREEN);
pinConfigBuilder.setGlyph(glyphText)
val pinConfig: PinConfig = pinConfigBuilder.build()
Java
// Set the glyph text.
PinConfig.Builder pinConfigBuilder = PinConfig.builder();
PinConfig.Glyph glyphText = new PinConfig.Glyph("A");
// Alternatively, you can set the text color:
// PinConfig.Glyph glyphText = new PinConfig.Glyph("A", Color.GREEN);
pinConfigBuilder.setGlyph(glyphText);
PinConfig pinConfig = pinConfigBuilder.build();
글리프 색상을 설정합니다.
Kotlin
val glyphColor = PinConfig.Glyph(Color.BLUE)
pinConfigBuilder.setGlyph(glyphColor)
val pinConfig: PinConfig = pinConfigBuilder.build()
Java
PinConfig.Glyph glyphColor = new PinConfig.Glyph(Color.BLUE);
pinConfigBuilder.setGlyph(glyphColor);
PinConfig pinConfig = pinConfigBuilder.build();
글리프로 사용할 맞춤 이미지를 설정합니다. 마커에 맞춤 로고와 같은 시각적인 표시를 사용하고 싶은 경우 이 기술이 유용합니다.
Kotlin
// Set the glyph image.
val glyphImage: Int = R.drawable.example_image
val descriptor = PinConfig.BitmapDescriptorFactory.fromResource(glyphImage)
pinConfigBuilder.setGlyph(Glyph(descriptor))
val pinConfig: PinConfig = pinConfigBuilder.build()
Java
// Set the glyph image.
int glyphImage = R.drawable.example_image;
BitmapDescriptor descriptor = BitmapDescriptorFactory.fromResource(glyphImage);
pinConfigBuilder.setGlyph(new PinConfig.Glyph(descriptor));
PinConfig pinConfig = pinConfigBuilder.build();
글리프 숨기기
마커 전체를 배경 색상으로 채우기 위해 글리프를 숨길 수도 있습니다.
Kotlin
// Create a transparent glyph.
val pinConfigBuilder: PinConfig.Builder = PinConfig.builder()
pinConfigBuilder.setBackgroundColor(Color.MAGENTA)
pinConfigBuilder.setGlyph(PinConfig.Glyph(Color.TRANSPARENT))
val pinConfig: PinConfig = pinConfigBuilder.build()
AdvancedMarkerOptions.iconView() 메서드를 사용하면 모든 Android View를 마커로 이용할 수 있습니다. 뷰를 마커로 사용하면 마커를 완전히 제어할 수 있습니다.
앱에서 먼저 뷰를 만든 다음 AdvancedMarkerOptions.iconView() 메서드를 사용하여 고급 마커에 뷰를 추가합니다.
Kotlin
// Create a TextView to use as the marker.
val textView = TextView(this)
textView.text = "Hello!!"
textView.setBackgroundColor(Color.BLACK)
textView.setTextColor(Color.YELLOW)
val marker: Marker? = map.addMarker(
AdvancedMarkerOptions()
.position(SYDNEY)
.iconView(textView)
)
Java
// Create a TextView to use as the marker.
TextView textView = new TextView(this);
textView.setText("Hello!!");
textView.setBackgroundColor(Color.BLACK);
textView.setTextColor(Color.YELLOW);
Marker marker = map.addMarker(
new AdvancedMarkerOptions()
.position(SYDNEY)
.iconView(textView));
[null,null,["최종 업데이트: 2024-05-09(UTC)"],[[["\u003cp\u003eAdvanced markers can be added to a map by creating an \u003ccode\u003eAdvancedMarkerOptions\u003c/code\u003e instance and using \u003ccode\u003eGoogleMap.addMarker()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eCustomize advanced marker properties, such as background color, border color, and glyph, by creating and configuring a \u003ccode\u003ePinConfig\u003c/code\u003e instance.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003eAdvancedMarkerOptions.iconView()\u003c/code\u003e method to utilize any Android View as the marker, offering complete customization control but potentially impacting performance.\u003c/p\u003e\n"],["\u003cp\u003eWhen using a \u003ccode\u003eView\u003c/code\u003e as a marker, manipulate the \u003ccode\u003eMarker\u003c/code\u003e itself for operations like rotation instead of directly modifying the \u003ccode\u003eView\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFurther customization options include changing the background and border colors, setting the glyph, and hiding the glyph for a filled background.\u003c/p\u003e\n"]]],[],null,["# Create an advanced marker\n\nSelect platform: [Android](/maps/documentation/android-sdk/advanced-markers/add-marker \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/advanced-markers/add-marker \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/advanced-markers/add-marker \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nTo add advanced markers to a map, create a new instance of\n[`AdvancedMarkerOptions`](/android/reference/com/google/android/gms/maps/model/AdvancedMarkerOptions)\nand then use\n[`GoogleMap.addMarker()`](/android/reference/com/google/android/gms/maps/GoogleMap#addMarker(com.google.android.gms.maps.model.MarkerOptions))\nto add the marker: \n\n### Kotlin\n\n\n```kotlin\nprivate val SYDNEY = LatLng(-33.87365, 151.20689)\n\nval marker: Marker? = map.addMarker(\n AdvancedMarkerOptions()\n .position(SYDNEY)\n .iconView(textView)\n .zIndex(zIndex)\n)\n```\n\n\u003cbr /\u003e\n\n### Java\n\n\n```java\nprivate final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);\n\nMarker marker = map.addMarker(\n new AdvancedMarkerOptions()\n .position(SYDNEY)\n .iconView(textView)\n .zIndex(zIndex));\n```\n\n\u003cbr /\u003e\n\n`GoogleMap.addMarker()` returns an instance of\n[`Marker`](/android/reference/com/google/android/gms/maps/model/Marker).\nIf necessary, you can cast the returned value to\n[`AdvancedMarker`](/android/reference/com/google/android/gms/maps/model/AdvancedMarker).\n\nUse `AdvancedMarkerOptions` to configure advanced markers.\n`AdvancedMarkerOptions` is a subclass of\n[`MarkerOptions`](/android/reference/com/google/android/gms/maps/model/MarkerOptions)\nso it supports all the same settings as `MarkerOptions`.\n\n`AdvancedMarkerOptions` also lets you:\n\n- Create an instance of the\n [`PinConfig`](/android/reference/com/google/android/gms/maps/model/PinConfig)\n class, and then use the `PinConfig`\n instance to configure the `AdvancedMarkerOptions` instance.\n\n Use `PinConfig` to customize advanced marker properties, such as the\n background color, border color, and glyph.\n- Create an instance of the Android\n [`View`](https://developer.android.com/reference/android/view/View) class\n and use that instance to configure the `AdvancedMarkerOptions` instance.\n\n The View instance lets you fully customize the marker.\n\nUse PinConfig\n-------------\n\nThe `PinConfig` class contains options to customize\nadvanced markers. Use `PinConfig` to:\n\n- Change the background color\n- Change the border color\n- Change the glyph color or add text\n- Hide the glyph\n\n**Figure 1**: The parts of an Advanced Marker.\n\nUse [`PinConfig.Builder`](/android/reference/com/google/android/gms/maps/model/PinConfig.Builder)\nto create an instance of `PinConfig`: \n\n### Kotlin\n\n\n```kotlin\n// Use PinConfig.Builder to create an instance of PinConfig.\nval pinConfigBuilder: PinConfig.Builder = PinConfig.builder()\npinConfigBuilder.setBackgroundColor(Color.MAGENTA)\nval pinConfig: PinConfig = pinConfigBuilder.build()\n\n// Use the PinConfig instance to set the icon for AdvancedMarkerOptions.\nval advancedMarkerOptions: AdvancedMarkerOptions = AdvancedMarkerOptions()\n .icon(BitmapDescriptorFactory.fromPinConfig(pinConfig))\n .position(MARKER_POSITION)\n\n// Pass the AdvancedMarkerOptions instance to addMarker().\nval marker: Marker? = map.addMarker(advancedMarkerOptions)\n```\n\n\u003cbr /\u003e\n\n### Java\n\n\n```java\n// Use PinConfig.Builder to create an instance of PinConfig.\nPinConfig.Builder pinConfigBuilder = PinConfig.builder();\npinConfigBuilder.setBackgroundColor(Color.MAGENTA);\nPinConfig pinConfig = pinConfigBuilder.build();\n\n// Use the PinConfig instance to set the icon for AdvancedMarkerOptions.\nAdvancedMarkerOptions advancedMarkerOptions =\n new AdvancedMarkerOptions()\n .icon(BitmapDescriptorFactory.fromPinConfig(pinConfig))\n .position(MARKER_POSITION);\n\n// Pass the AdvancedMarkerOptions instance to addMarker().\nMarker marker = map.addMarker(advancedMarkerOptions);\n```\n\n\u003cbr /\u003e\n\n### Change the background color\n\nUse the `PinConfig.background()` method to change the background color of a\nmarker: \n\n### Kotlin\n\n\n```kotlin\n// Use PinConfig.Builder to create an instance of PinConfig.\nval pinConfigBuilder: PinConfig.Builder = PinConfig.builder()\npinConfigBuilder.setBackgroundColor(Color.MAGENTA)\nval pinConfig: PinConfig = pinConfigBuilder.build()\n```\n\n\u003cbr /\u003e\n\n### Java\n\n\n```java\n// Use PinConfig.Builder to create an instance of PinConfig.\nPinConfig.Builder pinConfigBuilder = PinConfig.builder();\npinConfigBuilder.setBackgroundColor(Color.MAGENTA);\nPinConfig pinConfig = pinConfigBuilder.build();\n```\n\n\u003cbr /\u003e\n\n### Change the border color\n\nUse the `PinConfig.borderColor()` method to change the border color of a\nmarker: \n\n### Kotlin\n\n\n```kotlin\n// Set the border color.\nval pinConfigBuilder: PinConfig.Builder = PinConfig.builder()\npinConfigBuilder.setBorderColor(Color.BLUE)\nval pinConfig: PinConfig = pinConfigBuilder.build()\n```\n\n\u003cbr /\u003e\n\n### Java\n\n\n```java\n// Set the border color.\nPinConfig.Builder pinConfigBuilder = PinConfig.builder();\npinConfigBuilder.setBorderColor(Color.BLUE);\nPinConfig pinConfig = pinConfigBuilder.build();\n```\n\n\u003cbr /\u003e\n\n### Change the glyph\n\nCreate a [`Glyph`](/android/reference/com/google/android/gms/maps/model/PinConfig.Glyph)\ninstance and then use that instance to configure `PinConfig`.\nUse the glyph to set the glyph text and text color, the glyph color, or to\nspecify a custom image to use as the glyph.\n\nThe following example sets the glyph text: \n\n### Kotlin\n\n\n```kotlin\n// Set the glyph text.\nval pinConfigBuilder: PinConfig.Builder = PinConfig.builder()\nval glyphText = Glyph(\"A\")\n\n// Alteratively, you can set the text color:\n// Glyph glyphText = new Glyph(\"A\", Color.GREEN);\n\npinConfigBuilder.setGlyph(glyphText)\nval pinConfig: PinConfig = pinConfigBuilder.build()\n```\n\n\u003cbr /\u003e\n\n### Java\n\n\n```java\n// Set the glyph text.\nPinConfig.Builder pinConfigBuilder = PinConfig.builder();\nPinConfig.Glyph glyphText = new PinConfig.Glyph(\"A\");\n\n// Alternatively, you can set the text color:\n// PinConfig.Glyph glyphText = new PinConfig.Glyph(\"A\", Color.GREEN);\n\npinConfigBuilder.setGlyph(glyphText);\nPinConfig pinConfig = pinConfigBuilder.build();\n```\n\n\u003cbr /\u003e\n\nSet the glyph color: \n\n### Kotlin\n\n\n```kotlin\nval glyphColor = PinConfig.Glyph(Color.BLUE)\npinConfigBuilder.setGlyph(glyphColor)\nval pinConfig: PinConfig = pinConfigBuilder.build()\n```\n\n\u003cbr /\u003e\n\n### Java\n\n\n```java\nPinConfig.Glyph glyphColor = new PinConfig.Glyph(Color.BLUE);\npinConfigBuilder.setGlyph(glyphColor);\nPinConfig pinConfig = pinConfigBuilder.build();\n```\n\n\u003cbr /\u003e\n\nSet a custom image for the glyph. This technique is useful if you want to use a\ncustom logo or other visual indicator in the marker. \n\n### Kotlin\n\n\n```kotlin\n// Set the glyph image.\nval glyphImage: Int = R.drawable.example_image\nval descriptor = PinConfig.BitmapDescriptorFactory.fromResource(glyphImage)\npinConfigBuilder.setGlyph(Glyph(descriptor))\nval pinConfig: PinConfig = pinConfigBuilder.build()\n```\n\n\u003cbr /\u003e\n\n### Java\n\n\n```java\n// Set the glyph image.\nint glyphImage = R.drawable.example_image;\nBitmapDescriptor descriptor = BitmapDescriptorFactory.fromResource(glyphImage);\npinConfigBuilder.setGlyph(new PinConfig.Glyph(descriptor));\nPinConfig pinConfig = pinConfigBuilder.build();\n```\n\n\u003cbr /\u003e\n\n### Hide the glyph\n\nYou can hide the glyph so that the background color fills the entire marker: \n\n### Kotlin\n\n\n```kotlin\n// Create a transparent glyph.\nval pinConfigBuilder: PinConfig.Builder = PinConfig.builder()\npinConfigBuilder.setBackgroundColor(Color.MAGENTA)\npinConfigBuilder.setGlyph(PinConfig.Glyph(Color.TRANSPARENT))\nval pinConfig: PinConfig = pinConfigBuilder.build()\n```\n\n\u003cbr /\u003e\n\n### Java\n\n\n```java\n// Create a transparent glyph.\nPinConfig.Builder pinConfigBuilder = PinConfig.builder();\npinConfigBuilder.setBackgroundColor(Color.MAGENTA);\npinConfigBuilder.setGlyph(new PinConfig.Glyph(Color.TRANSPARENT));\nPinConfig pinConfig = pinConfigBuilder.build();\n```\n\n\u003cbr /\u003e\n\nUse iconView\n------------\n\nThe `AdvancedMarkerOptions.iconView()` method lets you use any Android\n[`View`](https://developer.android.com/reference/android/view/View)\nas the marker. By using a view as the marker, you have complete control over the\nmarker.\n| **Note:** When using a `View` as the marker, don't perform operation on the `View` to move it. Instead, modify the `Marker` itself. For example, to rotate the `View`, use the [`Marker.setRotation()`](/android/reference/com/google/android/gms/maps/model/Marker#setRotation(float)) method. Don't rotate `View`.\n\nIn your app, you first create the view, then use the\n`AdvancedMarkerOptions.iconView()` method to add the view to the\nadvanced markers. \n\n### Kotlin\n\n\n```kotlin\n// Create a TextView to use as the marker.\nval textView = TextView(this)\ntextView.text = \"Hello!!\"\ntextView.setBackgroundColor(Color.BLACK)\ntextView.setTextColor(Color.YELLOW)\n\nval marker: Marker? = map.addMarker(\n AdvancedMarkerOptions()\n .position(SYDNEY)\n .iconView(textView)\n)\n```\n\n\u003cbr /\u003e\n\n### Java\n\n\n```java\n// Create a TextView to use as the marker.\nTextView textView = new TextView(this);\ntextView.setText(\"Hello!!\");\ntextView.setBackgroundColor(Color.BLACK);\ntextView.setTextColor(Color.YELLOW);\n\nMarker marker = map.addMarker(\n new AdvancedMarkerOptions()\n .position(SYDNEY)\n .iconView(textView));\n```\n\n\u003cbr /\u003e\n\n| **Caution:** Performance of a map view with `iconView` markers might not match the performance of bitmap or default markers.\n\nNext steps:\n-----------\n\n- [Collision behavior](/maps/documentation/android-sdk/advanced-markers/collision-behavior)"]]