กำหนดค่าการหยุดชะงักแบบเรียลไทม์
การหยุดชะงักแบบเรียลไทม์คือชุดฟีเจอร์ที่แจ้งเตือนผู้ใช้เกี่ยวกับการหยุดชะงัก ตามเส้นทาง และช่วยให้ผู้ใช้รายงานและยืนยันการหยุดชะงักที่พบได้ ตัวอย่างของการหยุดชะงัก ได้แก่ อุบัติเหตุจากยานพาหนะ การจราจรติดขัด การปรากฏตัวของตำรวจและกล้องจับความเร็ว การก่อสร้าง การปิดช่องจราจร และสภาพอากาศบางอย่าง หน้านี้อธิบายฟีเจอร์การหยุดชะงักแบบเรียลไทม์และตัวเลือกการกำหนดค่า รวมถึงข้อควรพิจารณาสำหรับแอปที่ใช้ UI การนำทางที่กำหนดเอง
ฟีเจอร์การหยุดชะงักแบบเรียลไทม์
Navigation SDK มีฟีเจอร์การหยุดชะงักแบบเรียลไทม์ต่อไปนี้ซึ่งเป็นส่วนหนึ่งของประสบการณ์การนำทางหลัก- ข้อความไฮไลต์การหยุดชะงักแบบอินเทอร์แอกทีฟตามเส้นทาง
- การแจ้งเตือนการหยุดชะงักอัตโนมัติพร้อมการโหวตระหว่างการนำทางที่ใช้งานอยู่
- การรายงานการหยุดชะงักระหว่างการนำทางที่ใช้งานอยู่
ฟีเจอร์เหล่านี้กำหนดค่าได้และเปิดใช้อยู่โดยค่าเริ่มต้น ส่วนต่อไปนี้จะให้ข้อมูลเพิ่มเติมเกี่ยวกับฟีเจอร์และตัวเลือกการกำหนดค่าที่มี
ข้อความไฮไลต์การหยุดชะงักแบบอินเทอร์แอกทีฟตามเส้นทาง
เมื่อแอปแสดงเส้นทาง ไม่ว่าจะเป็นในภาพรวมเส้นทางหรือระหว่างการนำทางที่ใช้งานอยู่ การหยุดชะงักในปัจจุบันจะปรากฏเป็นข้อความอธิบายตามเส้นทาง ข้อความไฮไลต์จะมีไอคอนที่ระบุประเภทการหยุดชะงัก

คุณสามารถควบคุมการแสดงข้อความไฮไลต์การหยุดชะงักตามเส้นทางได้โดยใช้ shouldDisplayPrompts
ซึ่งจะควบคุมการแสดงการแจ้งเตือนอัตโนมัติเมื่อผู้ใช้เข้าใกล้การหยุดชะงักด้วย
mapView.navigator.shouldDisplayPrompts = true
แสดงรายละเอียดการหยุดชะงักเมื่อผู้ใช้แตะข้อความไฮไลต์
ผู้ใช้สามารถแตะข้อความไฮไลต์เพื่อแสดงการ์ดข้อมูลที่มีข้อมูลเพิ่มเติมเกี่ยวกับการหยุดชะงัก ซึ่งรวมถึงประเภทการหยุดชะงัก เวลาที่มีการรายงานล่าสุด และในบางกรณีจะมีตัวเลือกสำหรับ การโหวตว่าการหยุดชะงักยังคงเกิดขึ้นอยู่หรือไม่ การ์ดข้อมูลมี 2 ประเภท ซึ่งอาจปรากฏขึ้น ทั้งนี้ขึ้นอยู่กับว่าผู้ใช้กำลังนำทางอยู่หรือไม่ และตัวเลือกการกำหนดค่า จะแตกต่างกันไปในแต่ละประเภท
การ์ดข้อมูลข้อความไฮไลต์ในภาพรวมเส้นทางก่อนเริ่มการนำทางที่ใช้งานอยู่
เมื่อผู้ใช้แตะข้อความไฮไลต์ในภาพรวมเส้นทางก่อนเริ่มการนำทางที่ใช้งานอยู่ การ์ดข้อมูล จะปรากฏขึ้นพร้อมข้อมูลเพิ่มเติมเกี่ยวกับการหยุดชะงัก

คุณสามารถควบคุมความสามารถของผู้ใช้ในการแตะข้อความไฮไลต์การหยุดชะงักในภาพรวมเส้นทางเพื่อแสดงข้อมูลเพิ่มเติมได้โดยใช้ showsIncidentCards
mapView.settings.showsIncidentCards = true
การ์ดข้อมูลข้อความไฮไลต์ระหว่างการนำทางที่ใช้งานอยู่
เมื่อข้อความไฮไลต์การหยุดชะงักปรากฏขึ้นตามเส้นทางในระหว่างการนำทางที่ใช้งานอยู่ ผู้ใช้สามารถแตะข้อความไฮไลต์เพื่อแสดงการ์ดข้อมูลที่มีข้อมูลเพิ่มเติมเกี่ยวกับการหยุดชะงัก รวมถึงประเภทการหยุดชะงักและเวลาที่มีการรายงานล่าสุด ตลอดจนปุ่มสำหรับโหวตว่าการหยุดชะงักยังคงเกิดขึ้นอยู่หรือไม่ Google จะประมวลผลคะแนนที่ผู้ใช้ส่งและอาจแสดงคะแนนดังกล่าวในแผนที่ต่อ ผู้ใช้ Google Maps และผู้ใช้ Navigation SDK รายอื่นๆ รวมถึงใช้เพื่อพิจารณาว่าจะแสดง การหยุดชะงักต่อไปหรือไม่

คุณสามารถควบคุมการแสดงและการแตะข้อความไฮไลต์การหยุดชะงักระหว่างการนำทางที่ใช้งานอยู่ได้โดยใช้
shouldDisplayPrompts
ซึ่งจะควบคุม
การแสดงข้อความไฮไลต์ตามเส้นทางและ
การแสดงการแจ้งเตือนอัตโนมัติเมื่อผู้ใช้เข้าใกล้การหยุดชะงักด้วย
mapView.navigator.shouldDisplayPrompts = true
การแจ้งเตือนการหยุดชะงักอัตโนมัติพร้อมการโหวตระหว่างการนำทางที่ใช้งานอยู่
ในระหว่างการนำทางที่ใช้งานอยู่ เมื่อผู้ใช้เข้าใกล้การหยุดชะงักตามเส้นทาง ระบบจะแสดงข้อความพร้อม ข้อมูลเกี่ยวกับการหยุดชะงักและปุ่มสำหรับโหวตว่ายังมีการหยุดชะงักอยู่หรือไม่ Google จะประมวลผลคะแนนที่ผู้ใช้ส่งและอาจแสดงคะแนนดังกล่าวในแผนที่สำหรับ ผู้ใช้ Google Maps และ Navigation SDK รายอื่นๆ รวมถึงใช้เพื่อพิจารณาว่าจะแสดงการหยุดชะงักต่อไปหรือไม่

คุณสามารถกำหนดค่าการแสดงข้อความแจ้งการแจ้งเตือนระหว่างการนำทางที่ใช้งานอยู่ได้โดยใช้
shouldDisplayPrompts
ซึ่งจะควบคุมการแสดง
ข้อความไฮไลต์ตามเส้นทางด้วย
mapView.navigator.shouldDisplayPrompts = true
การรายงานการหยุดชะงักระหว่างการนำทางที่ใช้งานอยู่
ในโหมดการนำทางที่ใช้งานอยู่ ปุ่มจะปรากฏใน UI การนำทาง ซึ่งช่วยให้ผู้ใช้รายงานการหยุดชะงักใหม่ๆ ตามเส้นทางได้ เมื่อผู้ใช้แตะปุ่ม เมนูที่มีประเภทการหยุดชะงักที่รายงานได้จะปรากฏขึ้น Google จะประมวลผลรายงานที่ผู้ใช้ส่งและอาจแสดงรายงานดังกล่าวในแผนที่สำหรับผู้ใช้ Google Maps และ Navigation SDK คนอื่นๆ


แสดงหรือซ่อนปุ่มการรายงานมาตรฐาน
คุณกำหนดค่าระดับการมองเห็นของปุ่มการรายงานมาตรฐานในระหว่างการนำทางที่ใช้งานอยู่ได้โดยใช้
navigationReportIncidentButtonEnabled
// Enables the incident reporting FAB to show in situations where incident // reporting is possible. mapView.settings.navigationReportIncidentButtonEnabled = true
เพิ่มปุ่มรายงานที่กำหนดเอง
คุณสามารถเพิ่มปุ่มรายงานการหยุดชะงักที่กำหนดเองลงใน UI การนำทางแทนปุ่มรายงานการหยุดชะงักมาตรฐานได้ เมื่อผู้ใช้คลิกปุ่มที่กำหนดเอง คุณจะทริกเกอร์การแสดงเมนูการรายงานได้โดยเรียกใช้เมธอด 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. } }
ทำงานกับ UI การนำทางที่กำหนดเอง
หากการติดตั้งใช้งาน Navigation SDK มีองค์ประกอบ UI ที่กำหนดเอง คุณต้องพิจารณาองค์ประกอบการหยุดชะงักแบบเรียลไทม์เพื่อหลีกเลี่ยงความขัดแย้ง
การวางตำแหน่งปุ่มรายงาน
โดยค่าเริ่มต้น ปุ่มรายงานการหยุดชะงักจะอยู่ที่มุมด้านล่าง/ท้ายของแผนที่ โดยจะอยู่ทางด้านขวาสำหรับภาษาที่อ่านจากซ้ายไปขวา และอยู่ทางด้านซ้ายสำหรับภาษาที่อ่านจากขวาไปซ้าย หากต้องการย้ายปุ่มการรายงานเพื่อเพิ่มพื้นที่สำหรับองค์ประกอบ UI ที่กำหนดเอง ให้ใช้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 (ทดลอง)
Prompt Visibility API ช่วยให้คุณหลีกเลี่ยงความขัดแย้งระหว่างองค์ประกอบ UI ที่สร้างโดย Navigation SDK กับองค์ประกอบ UI ที่กำหนดเองของคุณเองได้โดยการเพิ่ม Listener เพื่อรับ Callback ก่อนที่องค์ประกอบ UI ของ Navigation SDK จะปรากฏขึ้น และทันทีที่นำองค์ประกอบออก คุณจะได้รับ การเรียกกลับสำหรับองค์ประกอบการหยุดชะงักแบบเรียลไทม์ ซึ่งรวมถึงการ์ดข้อมูล พรอมต์ และเมนูการรายงานการหยุดชะงัก รวมถึงการแจ้งเตือนอื่นๆ ที่สร้างโดย Navigation SDKSwift
// 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. } ...