אני רוצה לנסות

כדי להגדיר סגנון מבוסס-נתונים למערכי נתונים, פועלים לפי השלבים הבאים.

קבלת מפתח API והפעלת ממשקי API

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

יצירת מזהה מפה

mapID הוא מזהה ייחודי שמייצג מופע בודד של מפת Google. אפשר ליצור מזהי מפות ולעדכן סגנון שמשויך למזהה מפה בכל שלב במסוף Google Cloud.

צילום מסך של Google Cloud
מסוף

יצירת סגנון מפה חדש

כדי ליצור סגנון מפה חדש, פועלים לפי ההוראות במאמר ניהול המפה סגנונות ליצירה את הסגנון. בסיום התהליך, משייכים את הסגנון למזהה המפה החדש שנוצר.

עדכון הקוד של אתחול המפה

בשלב הזה, יש לשייך מזהה מפה לסגנון של תכונה אחת או יותר השכבות שהופעלו. כדי לאמת שמזהה המפה מוגדר בצורה נכונה ב: במסוף Cloud, כדאי לבדוק איך הוא מוגדר במפות Google ניהול.

Swift

// A map ID using a style with one or more feature layers enabled

let mapID = GMSMapID(identifier: "YOUR_MAP_ID")
let mapView = GMSMapView(frame: .zero, mapID: mapID, camera: GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7))

Objective-C

// A map ID using a style with one or more feature layers enabled

GMSMapID *mapID = [GMSMapID mapIDWithIdentifier:@"MAP_ID"];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:mapID camera:[GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]];

בדיקת יכולות המפה

סגנון מבוסס-נתונים למערכי נתונים דורש יכולות שמופעלות ומשויך למזהה מפה. מאחר שמזהי מפות כפופים ל אתם יכולים לבצע קריאה mapView.mapCapabilities על GMSMapView כדי לבדוק אם יכולת מסוימת (לדוגמה, סגנון מבוסס-נתונים) לפני ההתקשרות אליו.

תוכלו גם לזהות שינויים ביכולות המפה על ידי הרשמה אל GMSViewDelegate הדוגמה הזו מראה איך להשתמש בפרוטוקול כדי לבדוק סגנון מבוסס-נתונים בדרישות שלנו.

Swift

class SampleViewController: UIViewController {

  private lazy var mapView: GMSMapView = GMSMapView(frame: .zero, mapID: GMSMapID(identifier: "YOUR_MAP_ID"), camera: GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7))

  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 {
  GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:[GMSMapID mapIDWithIdentifier:@"MAP_ID"] camera:[GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]];
  mapView.delegete = 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

השלבים הבאים