כדי להגדיר את הסגנון מבוסס-הנתונים עבור מערכי נתונים, פועלים לפי השלבים הבאים.
קבלת מפתח API והפעלת ממשקי API
לפני שמשתמשים בסגנון מבוסס-נתונים של קבוצות נתונים, צריך: פרויקט בענן עם חשבון לחיוב, וגם את SDK של מפות ל-iOS ואת Maps Datasets API מופעלים. מידע נוסף זמין במאמרים הבאים:
יצירת מזהה מפה
מזהה מפה הוא מזהה ייחודי שמייצג מפרט של מפת Google. במסוף Google Cloud אפשר ליצור מזהי מפות ולעדכן סגנון שמשויך למזהה מפה בכל שלב.

יצירת סגנון מפה חדש
כדי ליצור סגנון מפה חדש, פועלים לפי ההוראות במאמר איך יוצרים סגנונות מפה ומשתמשים בהם. אחרי שיוצרים את מזהה המפה החדש, מקשרים אליו את הסגנון.
עדכון קוד ההפעלה של המפה
בשלב הזה צריך לשייך מזהה מפה לסגנון עם שכבת תכונות אחת או יותר שמופעלות. כדי לוודא שמזהה המפה מוגדר בצורה נכונה במסוף Cloud, בודקים את ההגדרה שלו בקטע ניהול מפות.
Swift
// A map ID using a style with one or more feature layers enabled let mapID = GMSMapID(identifier: "YOUR_MAP_ID") let camera = GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7) let options = GMSMapViewOptions() options.camera = camera options.mapID = mapID let mapView = GMSMapView(options: options)
Objective-C
// A map ID using a style with one or more feature layers enabled GMSMapID *mapID = [GMSMapID mapIDWithIdentifier:@"MAP_ID"]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]; GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init]; options.camera = camera; options.mapID = mapID; GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options];
בדיקת יכולות המפה
כדי להשתמש בסגנון מבוסס-נתונים של מערכי נתונים, צריך להפעיל יכולות במסוף Google Cloud ולשייך אותן למזהה מפה. מכיוון שמזהי מפות עשויים להשתנות, אפשר להפעיל את mapView.mapCapabilities ב-GMSMapView כדי לוודא שיכולת מסוימת (לדוגמה, עיצוב מבוסס-נתונים) זמינה לפני שמפעילים אותה.
אפשר גם להירשם לGMSViewDelegate כדי לקבל עדכונים על שינויים ביכולות של מפות Google.
בדוגמה הזו מוצג איך להשתמש בפרוטוקול כדי לבדוק את הדרישות של סגנון מבוסס-נתונים.
Swift
class SampleViewController: UIViewController { private lazy var mapView: GMSMapView = { let options = GMSMapViewOptions() options.mapID = GMSMapID(identifier: "YOUR_MAP_ID") options.camera = GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7) return GMSMapView(options: options) }() override func loadView() { self.view = mapView mapView.delegate = self } } extension SampleViewController: GMSMapViewDelegate { func mapView(_ mapView: GMSMapView, didChange mapCapabilities: GMSMapCapabilityFlags) { if (!mapCapabilities.contains(.dataDrivenStyling)) { // Data-driven styling is *not* available, add a fallback. // Existing feature layers are also unavailable. } } }
Objective-C
@interface SampleViewController: UIViewController <GMSMapViewDelegate> @end @implementation SampleViewController - (void)loadView { GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]; GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init]; options.camera = camera; options.mapID = [GMSMapID mapIDWithIdentifier:@"MAP_ID"]; GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options]; mapView.delegate = self; self.view = mapView; } - (void)mapView:(GMSMapView *)mapView didChangeMapCapabilities:(GMSMapCapabilityFlags)mapCapabilities { if (!(mapCapabilities & GMSMapCapabilityFlagsDataDrivenStyling)) { // Data-driven styling is *not* available, add a fallback. // Existing feature layers are also unavailable. } } @end