برای راهاندازی استایل مبتنی بر داده برای مجموعههای داده، این مراحل را دنبال کنید.
یک کلید API دریافت کنید و API ها را فعال کنید
قبل از استفاده از سبکهای مبتنی بر داده برای مجموعههای داده، به این موارد نیاز دارید: پروژه Cloud با حساب صورتحساب، و هم Maps SDK برای iOS و هم Maps Datasets API فعال باشد. برای کسب اطلاعات بیشتر، نگاه کنید به:
شناسه نقشه یک شناسه منحصر به فرد است که مشخصات نقشه گوگل را نشان می دهد. میتوانید شناسههای نقشه ایجاد کنید و سبک مرتبط با شناسه نقشه را در هر زمان در کنسول 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]];
بررسی قابلیت های نقشه
سبکسازی مبتنی بر داده برای مجموعههای داده به قابلیتهایی نیاز دارد که در کنسول 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-07-23 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-07-23 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eTo utilize data-driven styling for datasets within the Maps SDK for iOS, you must set up a Google Cloud project, enable necessary APIs (Maps SDK for iOS & Maps Datasets API), and acquire an API key.\u003c/p\u003e\n"],["\u003cp\u003eA unique map ID linked to a specific map style with enabled feature layers is crucial for loading datasets and using data-driven styling.\u003c/p\u003e\n"],["\u003cp\u003eBefore implementing data-driven styling features, ensure the map's capabilities are compatible by verifying through \u003ccode\u003emapView.mapCapabilities\u003c/code\u003e or subscribing to \u003ccode\u003eGMSViewDelegate\u003c/code\u003e to detect changes and handle potential fallbacks.\u003c/p\u003e\n"],["\u003cp\u003eInitialization of the map view requires using the designated map ID containing the desired style and feature layers for data-driven styling to function correctly.\u003c/p\u003e\n"],["\u003cp\u003eYou cannot utilize a demo map ID for data-driven styling as it necessitates a map ID specifically associated with a map style containing the dataset.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-datasets/start \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-datasets/start \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-datasets/start \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nFollow these steps to get set up with the data-driven styling for datasets.\n\nGet an API key and enable APIs\n\nBefore using data-driven styling for datasets, you need:\nCloud project with a billing account, and both the\nMaps SDK for iOS and the Maps Datasets API\nenabled. To learn more, see:\n\n- [Set up your Google Cloud project](/maps/documentation/ios-sdk/cloud-setup)\n\n- [Enable Maps SDK for iOS and get an API key](/maps/documentation/ios-sdk/get-api-key)\n\n- [Enable the Maps Datasets API](https://console.cloud.google.com/apis/library/mapsplatformdatasets.googleapis.com)\n\nCreate a map ID\n\nA [map ID](/maps/documentation/get-map-id) is a unique identifier that\nrepresents a Google Map specification. You can create map IDs and update\na style associated 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 [Create and use 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\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:** You cannot use a demo map ID because a map ID with the linked map style is needed to load the dataset to the client.\n\nCheck map capabilities\n\nData-driven styling for datasets 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\n[`GMSMapView`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView)\nto verify whether a certain capability (for example data-driven styling) is\navailable 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).\nThis example shows how to use the protocol to check for data-driven styling\nrequirements. \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```\n\nNext steps\n\n- [Create and manage a dataset](/maps/documentation/ios-sdk/dds-datasets/create-dataset)"]]