برای استفاده از استایل مبتنی بر داده برای مرزها، باید یک شناسه نقشه ایجاد کنید. در مرحله بعد، باید یک سبک نقشه جدید ایجاد کنید، لایههای ویژگی مرزی مورد نیاز را انتخاب کنید، و سبک را با شناسه نقشه خود مرتبط کنید.
یک شناسه نقشه ایجاد کنید
MapID یک شناسه منحصر به فرد است که یک نمونه از نقشه گوگل را نشان می دهد. میتوانید شناسههای نقشه ایجاد کنید و سبک مرتبط با شناسه نقشه را در هر زمان در کنسول Google Cloud بهروزرسانی کنید.
یک سبک نقشه جدید ایجاد کنید
برای ایجاد یک سبک نقشه جدید، دستورالعمل های موجود در Manage map styles را برای ایجاد سبک دنبال کنید. پس از تکمیل استایل را با شناسه نقشه جدید ایجاد شده مرتبط کنید.
لایه های ویژگی را انتخاب کنید
در کنسول Google Cloud می توانید انتخاب کنید که کدام لایه ویژگی نمایش داده شود. این تعیین می کند که چه نوع مرزهایی روی نقشه ظاهر می شوند (به عنوان مثال محلات، ایالت ها و غیره).
برای افزودن یا حذف لایهها، روی منوی کشویی لایههای ویژگی کلیک کنید.
برای ذخیره تغییرات و در دسترس قرار دادن آنها در نقشه های خود، روی ذخیره کلیک کنید.
کد اولیه نقشه خود را به روز کنید
این مرحله نیازمند شناسه نقشه است که با یک سبک با یک یا چند لایه ویژگی فعال باشد. برای تأیید اینکه شناسه نقشه شما به درستی در کنسول Cloud تنظیم شده است، نحوه پیکربندی آن را در مدیریت نقشه ها مرور کنید.
سویفت
// A map ID using a style with one or more feature layers enabledletmapID=GMSMapID(identifier:"YOUR_MAP_ID")letmapView=GMSMapView(frame:.zero,mapID:mapID,camera:GMSCameraPosition(latitude:40,longitude:-80,zoom:7))
هدف-C
// A map ID using a style with one or more feature layers enabledGMSMapID*mapID=[GMSMapIDmapIDWithIdentifier:@"MAP_ID"];GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZeromapID:mapIDcamera:[GMSCameraPositioncameraWithLatitude:40longitude:-80zoom:7]];
لایه های ویژگی را به نقشه اضافه کنید
برای دریافت ارجاع به یک لایه ویژگی روی نقشه خود، زمانی که نقشه مقداردهی اولیه شد، mapView.featureLayer(of:) را فراخوانی کنید:
سبکسازی مبتنی بر داده برای مرزها به قابلیتهایی نیاز دارد که در کنسول Google Cloud فعال شده و با شناسه نقشه مرتبط است. از آنجایی که شناسههای نقشه در معرض تغییر هستند، میتوانید با mapView.mapCapabilities در GMSMapView تماس بگیرید تا بررسی کنید که آیا یک قابلیت خاص (مثلاً سبکسازی مبتنی بر دادهها) قبل از تماس وجود دارد یا خیر.
همچنین میتوانید با عضویت در GMSViewDelegate تغییرات در قابلیتهای نقشه را شناسایی کنید. این مثال نحوه استفاده از پروتکل را برای بررسی الزامات استایل مبتنی بر داده نشان می دهد.
سویفت
classSampleViewController:UIViewController{privatelazyvarmapView:GMSMapView=GMSMapView(frame:.zero,mapID:GMSMapID(identifier:"YOUR_MAP_ID"),camera:GMSCameraPosition(latitude:40,longitude:-80,zoom:7))overridefuncloadView(){self.view=mapViewmapView.delegate=self}}extensionSampleViewController:GMSMapViewDelegate{funcmapView(_mapView:GMSMapView,didChangemapCapabilities:GMSMapCapabilityFlags){if(!mapCapabilities.contains(.dataDrivenStyling)){// Data-driven styling is *not* available, add a fallback.// Existing feature layers are also unavailable.}}}
هدف-C
@interfaceSampleViewController: UIViewController<GMSMapViewDelegate>
@end@implementationSampleViewController-(void)loadView{GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZeromapID:[GMSMapIDmapIDWithIdentifier:@"MAP_ID"]camera:[GMSCameraPositioncameraWithLatitude:40longitude:-80zoom:7]];mapView.delegete=self;self.view=mapView;}-(void)mapView:(GMSMapView*)mapViewdidChangeMapCapabilities:(GMSMapCapabilityFlags)mapCapabilities{if(!(mapCapabilities&GMSMapCapabilityFlagsDataDrivenStyling)){// Data-driven styling is *not* available, add a fallback.// Existing feature layers are also unavailable.}}@end
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eData-driven styling for boundaries requires creating a map ID and associating it with a custom map style that includes selected feature layers.\u003c/p\u003e\n"],["\u003cp\u003eYou can manage feature layers, such as localities and states, in the Google Cloud console to control which boundaries are displayed.\u003c/p\u003e\n"],["\u003cp\u003eUpdate your map initialization code to use the map ID, ensuring data-driven styling is enabled for the map.\u003c/p\u003e\n"],["\u003cp\u003eUtilize \u003ccode\u003emapView.featureLayer(of:)\u003c/code\u003e to access specific feature layers on your map for further styling or interaction.\u003c/p\u003e\n"],["\u003cp\u003eVerify map capabilities, including data-driven styling, using \u003ccode\u003emapView.mapCapabilities\u003c/code\u003e or by subscribing to \u003ccode\u003eGMSViewDelegate\u003c/code\u003e to detect changes and implement fallbacks if needed.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-boundaries/start \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-boundaries/start \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-boundaries/start \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nTo use data-driven styling for boundaries you must create a map ID. Next, you\nmust create a new map style, select the needed boundary feature layers, and\nassociate the style with your map ID.\n\nCreate a map ID\n\nA [mapID](/maps/documentation/get-map-id) is a unique identifier that represents\na single instance of a Google Map. You can create map IDs and update a style\nassociated with a map ID at any time in the Google Cloud console.\n\nCreate a new map style\n\nTo create a new map style, follow the instructions in [Manage map\nstyles](/maps/documentation/ios-sdk/cloud-customization/map-styles) to create\nthe style. Once complete associate the style with the newly created map ID.\n| **Experimental:** This feature can only be set for light map styles. When you link a light map style that has this feature enabled to a [map\n| ID](../map-ids/mapid-over), the enabled layers are also available for the dark map style.\n\nSelect feature layers\n\nIn the Google Cloud console you can select which feature layers to display. This\ndetermines which kinds of boundaries appear on the map (for example localities,\nstates, and so on).\n| **Important:** For optimal performance, only select the layers you need.\n\nManage feature layers\n\n1. In the Google Cloud console, [go to the Map Styles\n page](https://console.cloud.google.com/project/_/google/maps-apis/studio/styles)\n\n2. Select a project if prompted.\n\n3. Select a map style.\n\n4. Click the **Feature layers** drop-down to add or remove layers.\n\n5. Click **Save** to save your changes and make them available to your maps.\n\nUpdate your map initialization code\n\nThis step requires a map ID be associated with a style with one or more feature\nlayers enabled. To verify your map ID is set up correctly in\nCloud console, review how it is configured under [Maps\nManagement](https://console.cloud.google.com/google/maps-apis/studio/maps). \n\nSwift \n\n```swift\n// A map ID using a style with one or more feature layers enabled\n\nlet mapID = GMSMapID(identifier: \"YOUR_MAP_ID\")\nlet mapView = GMSMapView(frame: .zero, mapID: mapID, camera: GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7))\n```\n\nObjective-C \n\n```objective-c\n// A map ID using a style with one or more feature layers enabled\n\nGMSMapID *mapID = [GMSMapID mapIDWithIdentifier:@\"MAP_ID\"];\nGMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:mapID camera:[GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]];\n```\n| **Important:** For testing, you can skip the step of creating and configuring a [map\n| ID](/maps/documentation/get-map-id), by using mapId: [`DEMO_MAP_ID`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapID) in your app code. `DEMO_MAP_ID` is intended for testing purposes only. Don't use `DEMO_MAP_ID` in a production environment.\n\nAdd feature layers to a map\n\nTo get a reference to a feature layer on your map, call\n[`mapView.featureLayer(of:)`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView#-featurelayeroffeaturetype:)\nwhen the map initializes: \n\nSwift \n\n```swift\nlet layer = mapView.featureLayer(of: .locality)\n```\n\nObjective-C \n\n```objective-c\nGMSFeatureLayer *layer = [mapView featureLayerOfFeatureType:GMSFeatureTypeLocality];\n```\n\nCheck map capabilities\n\nData-driven styling for boundaries requires capabilities which are enabled in the\nGoogle Cloud console, and associated with a map ID. Because map IDs are subject to\nchange, you can call\n[`mapView.mapCapabilities`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView#mapcapabilities)\non a [`GMSMapView`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView) to verify whether a certain capability (for\nexample data-driven styling) is available prior to calling it.\n\nYou can also detect changes in map capabilities by subscribing to\n[`GMSViewDelegate`](/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate). This example shows how to use the\nprotocol to check for data-driven styling requirements. \n\nSwift \n\n```swift\nclass SampleViewController: UIViewController {\n\n private lazy var mapView: GMSMapView = GMSMapView(frame: .zero, mapID: GMSMapID(identifier: \"YOUR_MAP_ID\"), camera: GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7))\n\n override func loadView() {\n self.view = mapView\n mapView.delegate = self\n }\n}\n\nextension SampleViewController: GMSMapViewDelegate {\n func mapView(_ mapView: GMSMapView, didChange mapCapabilities: GMSMapCapabilityFlags) {\n if (!mapCapabilities.contains(.dataDrivenStyling)) {\n // Data-driven styling is *not* available, add a fallback.\n // Existing feature layers are also unavailable.\n }\n }\n}\n```\n\nObjective-C \n\n```objective-c\n@interface SampleViewController: UIViewController \u003cGMSMapViewDelegate\u003e\n@end\n\n@implementation SampleViewController\n- (void)loadView {\n GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:[GMSMapID mapIDWithIdentifier:@\"MAP_ID\"] camera:[GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]];\n mapView.delegete = self;\n self.view = mapView;\n}\n\n- (void)mapView:(GMSMapView *)mapView didChangeMapCapabilities:(GMSMapCapabilityFlags)mapCapabilities {\n if (!(mapCapabilities & GMSMapCapabilityFlagsDataDrivenStyling)) {\n // Data-driven styling is *not* available, add a fallback.\n // Existing feature layers are also unavailable.\n }\n}\n@end\n```"]]