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.valpinConfigBuilder:PinConfig.Builder=PinConfig.builder()pinConfigBuilder.setBackgroundColor(Color.MAGENTA)valpinConfig:PinConfig=pinConfigBuilder.build()
// Use the PinConfig instance to set the icon for AdvancedMarkerOptions.valadvancedMarkerOptions:AdvancedMarkerOptions=AdvancedMarkerOptions().icon(BitmapDescriptorFactory.fromPinConfig(pinConfig)).position(MARKER_POSITION)
// Pass the AdvancedMarkerOptions instance to addMarker().valmarker:Marker? =map.addMarker(advancedMarkerOptions)
جاوا
// Use PinConfig.Builder to create an instance of PinConfig.PinConfig.BuilderpinConfigBuilder=PinConfig.builder();pinConfigBuilder.setBackgroundColor(Color.MAGENTA);PinConfigpinConfig=pinConfigBuilder.build(); // Use the PinConfig instance to set the icon for AdvancedMarkerOptions.AdvancedMarkerOptionsadvancedMarkerOptions=newAdvancedMarkerOptions().icon(BitmapDescriptorFactory.fromPinConfig(pinConfig)).position(MARKER_POSITION); // Pass the AdvancedMarkerOptions instance to addMarker().Markermarker=map.addMarker(advancedMarkerOptions);
رنگ پس زمینه را تغییر دهید
از متد PinConfig.background() برای تغییر رنگ پس زمینه یک نشانگر استفاده کنید:
کاتلین
// Use PinConfig.Builder to create an instance of PinConfig.valpinConfigBuilder:PinConfig.Builder=PinConfig.builder()pinConfigBuilder.setBackgroundColor(Color.MAGENTA)valpinConfig:PinConfig=pinConfigBuilder.build()
جاوا
// Use PinConfig.Builder to create an instance of PinConfig.PinConfig.BuilderpinConfigBuilder=PinConfig.builder();pinConfigBuilder.setBackgroundColor(Color.MAGENTA);PinConfigpinConfig=pinConfigBuilder.build();
رنگ حاشیه را تغییر دهید
برای تغییر رنگ حاشیه یک نشانگر از روش PinConfig.borderColor() استفاده کنید:
کاتلین
// Set the border color.valpinConfigBuilder:PinConfig.Builder=PinConfig.builder()pinConfigBuilder.setBorderColor(Color.BLUE)valpinConfig:PinConfig=pinConfigBuilder.build()
جاوا
// Set the border color.PinConfig.BuilderpinConfigBuilder=PinConfig.builder();pinConfigBuilder.setBorderColor(Color.BLUE);PinConfigpinConfig=pinConfigBuilder.build();
گلیف را تغییر دهید
یک نمونه Glyph ایجاد کنید و سپس از آن نمونه برای پیکربندی PinConfig استفاده کنید. از علامت برای تنظیم متن و رنگ متن، رنگ علامت یا برای تعیین یک تصویر سفارشی برای استفاده به عنوان علامت استفاده کنید.
مثال زیر متن گلیف را تنظیم می کند:
کاتلین
// Set the glyph text.valpinConfigBuilder:PinConfig.Builder=PinConfig.builder()valglyphText=Glyph("A") // Alteratively, you can set the text color:// Glyph glyphText = new Glyph("A", Color.GREEN); pinConfigBuilder.setGlyph(glyphText)valpinConfig:PinConfig=pinConfigBuilder.build()
جاوا
// Set the glyph text.PinConfig.BuilderpinConfigBuilder=PinConfig.builder();PinConfig.GlyphglyphText=newPinConfig.Glyph("A"); // Alternatively, you can set the text color:// PinConfig.Glyph glyphText = new PinConfig.Glyph("A", Color.GREEN); pinConfigBuilder.setGlyph(glyphText);PinConfigpinConfig=pinConfigBuilder.build();
یک تصویر سفارشی برای گلیف تنظیم کنید. اگر می خواهید از یک لوگوی سفارشی یا سایر نشانگرهای بصری در نشانگر استفاده کنید، این تکنیک مفید است.
کاتلین
// Set the glyph image.valglyphImage:Int=R.drawable.example_imagevaldescriptor=PinConfig.BitmapDescriptorFactory.fromResource(glyphImage)pinConfigBuilder.setGlyph(Glyph(descriptor))valpinConfig:PinConfig=pinConfigBuilder.build()
جاوا
// Set the glyph image.intglyphImage=R.drawable.example_image;BitmapDescriptordescriptor=BitmapDescriptorFactory.fromResource(glyphImage);pinConfigBuilder.setGlyph(newPinConfig.Glyph(descriptor));PinConfigpinConfig=pinConfigBuilder.build();
گلیف را مخفی کنید
میتوانید گلیف را پنهان کنید تا رنگ پسزمینه کل نشانگر را پر کند:
کاتلین
// Create a transparent glyph.valpinConfigBuilder:PinConfig.Builder=PinConfig.builder()pinConfigBuilder.setBackgroundColor(Color.MAGENTA)pinConfigBuilder.setGlyph(PinConfig.Glyph(Color.TRANSPARENT))valpinConfig:PinConfig=pinConfigBuilder.build()
جاوا
// Create a transparent glyph.PinConfig.BuilderpinConfigBuilder=PinConfig.builder();pinConfigBuilder.setBackgroundColor(Color.MAGENTA);pinConfigBuilder.setGlyph(newPinConfig.Glyph(Color.TRANSPARENT));PinConfigpinConfig=pinConfigBuilder.build();
از iconView استفاده کنید
روش AdvancedMarkerOptions.iconView() به شما امکان می دهد از هر View Android به عنوان نشانگر استفاده کنید. با استفاده از نما به عنوان نشانگر، کنترل کاملی بر نشانگر دارید.
در برنامه خود، ابتدا نمای را ایجاد میکنید، سپس از متد AdvancedMarkerOptions.iconView() برای افزودن نما به نشانگرهای پیشرفته استفاده میکنید.
کاتلین
// Create a TextView to use as the marker.valtextView=TextView(this)textView.text="Hello!!"textView.setBackgroundColor(Color.BLACK)textView.setTextColor(Color.YELLOW) valmarker:Marker? =map.addMarker(AdvancedMarkerOptions().position(SYDNEY).iconView(textView))
جاوا
// Create a TextView to use as the marker.TextViewtextView=newTextView(this);textView.setText("Hello!!");textView.setBackgroundColor(Color.BLACK);textView.setTextColor(Color.YELLOW); Markermarker=map.addMarker(newAdvancedMarkerOptions().position(SYDNEY).iconView(textView));
تاریخ آخرین بهروزرسانی 2025-09-04 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-09-04 بهوقت ساعت هماهنگ جهانی."],[[["\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)"]]