בחירת פלטפורמה: Android iOS

הגדרת שיבושים בזמן אמת

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

תכונות לשיבושים בזמן אמת

‫Navigation SDK כולל את התכונות הבאות לשיבושים בזמן אמת כחלק מחוויית הניווט הבסיסית:

התכונות האלה ניתנות להגדרה ומופעלות כברירת מחדל. בקטעים הבאים מפורט מידע נוסף על התכונות ועל אפשרויות ההגדרה הזמינות.

הסברים אינטראקטיביים על שיבושים לאורך המסלולים

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

הדגשות לאורך המסלולים

אפשר לשלוט בהצגה של תיאורי שיבושים לאורך מסלולים באמצעות shouldDisplayPrompts, ששולט גם בהצגה של התראות אוטומטיות כשמשתמש מתקרב לשיבוש.

mapView.navigator.shouldDisplayPrompts = true

הצגת פרטי השיבוש כשמשתמש מקיש על הסבר

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

כרטיסי מידע עם הסברים על מסלולים, לפני שמתחילים בניווט פעיל

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

כרטיס מידע על סקירה כללית

אתם יכולים לקבוע אם משתמשים יוכלו להקיש על בועות מידע על שיבושים בנסיעה בתצוגות הכלליות של המסלולים כדי להציג מידע נוסף באמצעות showsIncidentCards.

mapView.settings.showsIncidentCards = true

כרטיסי מידע של הסברים במהלך ניווט פעיל

כשמוצג הסבר על שיבוש בדרך במהלך ניווט פעיל, המשתמשים יכולים להקיש על ההסבר כדי להציג כרטיס מידע עם פרטים נוספים על השיבוש, כולל סוג השיבוש והשעה שבה דווח עליו לאחרונה, וגם לחצנים להצבעה על כך שהשיבוש עדיין קיים. ההצבעות שנשלחות על ידי משתמשים עוברות עיבוד על ידי Google, ויכול להיות שהן יוצגו במפה למשתמשים אחרים במפות Google וב-Navigation SDK, וגם ישמשו לקביעה אם להמשיך להציג את השיבוש.

כרטיס מידע על ניווט פעיל

אתם יכולים לשלוט בהצגה של ההסברים על שיבושים ובאפשרות להקיש עליהם במהלך ניווט פעיל באמצעות shouldDisplayPrompts, ששולט גם בהצגת ההסברים לאורך המסלולים ובהצגת התראות אוטומטיות כשמשתמש מתקרב לשיבוש.

mapView.navigator.shouldDisplayPrompts = true

התראות אוטומטיות על שיבושים עם אפשרות הצבעה במהלך ניווט פעיל

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

כרטיס מידע על ניווט פעיל

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

mapView.navigator.shouldDisplayPrompts = true

דיווח על שיבושים במהלך ניווט פעיל

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

לחצן הדיווח תפריט הדיווח

הצגה או הסתרה של לחצן הדוחות הרגילים

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

// Enables the incident reporting FAB to show in situations where incident
// reporting is possible.
mapView.settings.navigationReportIncidentButtonEnabled = true

הוספה של לחצן דיווח בהתאמה אישית

במקום לחצן הדיווח הרגיל על שיבושים, אתם יכולים להוסיף לחצן דיווח בהתאמה אישית לממשק המשתמש של הניווט. כשמשתמש לוחץ על הלחצן המותאם אישית, אפשר להפעיל את הצגת תפריט הדיווח באמצעות הקריאה לשיטה presentReportIncidentsPanel. לפני שמוסיפים לחצן דיווח בהתאמה אישית, צריך לוודא שהאפליקציה נמצאת בניווט פעיל והמשתמש נמצא במדינה שבה הדיווח מופעל. לשם כך, קוראים ל-reportIncidentsAvailable. אם אחד מהתנאים האלה לא מתקיים, תפריט הדיווח לא יופיע.

  // Check if reporting is available before displaying your button
  let isReportingAvailable = mapview.isIncidentReportingAvailable()
  customReportingIncidentButton.isHidden = !isReportingAvailable
  customReportingIncidentButton.addTarget(self, action: #selector(didTapReportIncidentButton), for: .touchUpInside)
  
  // Trigger the reporting flow if the button is clicked
  func didTapReportIncidentButton() {
          mapView.presentReportIncidentsPanel(self) { [weak self] error in
              guard let self = self else { return }
              if let error = error as NSError? {
                  if error.domain == GMSMapViewPresentReportIncidentPanelErrorDomain {
                      let errorCode = GMSMapViewPresentReportIncidentPanelErrorCode(rawValue: error.code)
                      
                      switch errorCode {
                      case .internal:
                          self.showErrorMessage(
                              title: "Error Presenting Report Incident Panel",
                              message: "An internal error occurred."
                          )
                      case .reportingNotAvailable:
                          self.showErrorMessage(
                              title: "Error Presenting Report Incident Panel",
                              message: "Reporting is not available."
                          )
                      case .none:
                          self.showErrorMessage(
                              title: "Error Presenting Report Incident Panel",
                              message: "An unknown error occurred."
                          )
                      }
                  } else {
                      // Handle other potential errors (e.g., network errors)
                      self.showErrorMessage(
                          title: "Error Presenting Report Incident Panel",
                          message: "An unexpected error occurred: \(error.localizedDescription)"
                      )
                  }
              }
              // If error is nil, the panel was presented successfully. You can add any extra logic here.
          }
     }

עבודה עם ממשקי משתמש מותאמים אישית לניווט

אם ההטמעה של Navigation SDK כוללת רכיבי ממשק משתמש מותאמים אישית, צריך לקחת בחשבון את רכיבי השיבוש בזמן אמת כדי להימנע מקונפליקטים.

מיקום לחצן הדיווח

כברירת מחדל, לחצן הדיווח על שיבושים ממוקם בפינה התחתונה של המפה – בצד שמאל בשפות שקוראים משמאל לימין, ובצד ימין בשפות שקוראים מימין לשמאל. אם אתם צריכים להזיז את לחצן הדיווח כדי לפנות מקום לרכיבי ממשק משתמש בהתאמה אישית, אתם יכולים להשתמש ב-bottomTrailingButtonsLayoutGuide.

Swift

// Create a new layout guide
let topRightLayoutGuide = UILayoutGuide()
self.view.addLayoutGuide(topRightLayoutGuide)

// Activate constraints using fixed constants here as an example
// assuming the current reporting button is of fixed height
topRightLayoutGuide.topAnchor.constraint(equalTo: _mapView.navigationHeaderLayoutGuide.bottomAnchor, constant: 50).isActive = true
topRightLayoutGuide.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor, constant: -14).isActive = true

// Assign the layout guide
_mapView.bottomTrailingButtonsLayoutGuide = topRightLayoutGuide

// Create an alternate layout guide to use when the header and the footer are not full width
let topRightAlternateLayoutGuide = UILayoutGuide()
self.view.addLayoutGuide(topRightAlternateLayoutGuide)

// Activate constraints using fixed constants here as an example
// assuming the current RTD button is of fixed height
topRightAlternateLayoutGuide.topAnchor.constraint(equalTo: _mapView.navigationHeaderLayoutGuide.bottomAnchor, constant: 20).isActive = true
topRightAlternateLayoutGuide.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor, constant: -10).isActive = true

// Assign the layout guide
_mapView.bottomTrailingButtonsAlternateLayoutGuide = topRightAlternateLayoutGuide

Objective-C

// Create a new layout guide
UILayoutGuide *topRightLayoutGuide = [[UILayoutGuide alloc] init];
[self.view addLayoutGuide:topRightLayoutGuide];

// Activate constraints using fixed constants here as an example
// assuming the current RTD button is of fixed height
[[topRightLayoutGuide.topAnchor
    constraintEqualToAnchor:_mapView.navigationHeaderLayoutGuide.bottomAnchor
                   constant:50]
    setActive:YES];

[[topRightLayoutGuide.trailingAnchor
    constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor
                   constant:-14]
    setActive:YES];

// Assign the layout guide
_mapView.bottomTrailingButtonsLayoutGuide = topRightLayoutGuide;

// Create an alternate layout guide to use when the header and the footer are not full width
UILayoutGuide *topRightAlternateLayoutGuide = [[UILayoutGuide alloc] init];
[self.view addLayoutGuide:topRightAlternateLayoutGuide];

// Activate constraints using fixed constants here as an example
// assuming the current RTD button is of fixed height
[[topRightAlternateLayoutGuide.topAnchor
    constraintEqualToAnchor:_mapView.navigationHeaderLayoutGuide.bottomAnchor
                   constant:50]
    setActive:YES];

[[topRightAlternateLayoutGuide.trailingAnchor
    constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor
                   constant:-14]
    setActive:YES];

// Assign the layout guide
_mapView.bottomTrailingButtonsAlternateLayoutGuide = topRightAlternateLayoutGuide;

Prompt Visibility API (ניסיוני)

ה-API של Prompt Visibility עוזר לכם להימנע מקונפליקטים בין רכיבי ממשק משתמש שנוצרו על ידי Navigation SDK לבין רכיבי ממשק משתמש מותאמים אישית משלכם. הוא עושה זאת על ידי הוספת listener לקבלת קריאה חוזרת לפני שרכיב ממשק משתמש של Navigation SDK עומד להופיע, וברגע שהרכיב מוסר. אפשר לקבל קריאות חוזרות (callback) לגבי רכיבי שיבוש בזמן אמת, כולל כרטיסי מידע, הנחיות ותפריט הדיווח על שיבושים, וגם לגבי התראות אחרות שנוצרות על ידי Navigation SDK.

Swift

// Additional methods added to GMSNavigatorListener
...
func navigatorWillPresentPrompt(_ navigator: GMSNavigator) {
  // Hide any sort of custom UI element.
}

func navigatorDidDismissPrompt(_ navigator: GMSNavigator) {
  // Show any sort of custom UI element.
}
...

Objective-C

// Additional methods added to GMSNavigatorListener
...
- (void)navigatorWillPresentPrompt:(GMSNavigator *)navigator {
  // Hide any sort of custom UI element.
}

- (void)navigatorDidDismissPrompt:(GMSNavigator *)navigator {
  // Show any sort of custom UI element.
}
...