ฟังเหตุการณ์การนําทาง

ใช้คู่มือนี้เพื่อเปิดใช้แอปให้ฟังและตอบสนองต่อเหตุการณ์ต่างๆ ที่เปลี่ยนแปลงไปเมื่อผู้ใช้ไปยังส่วนต่างๆ ของเส้นทาง คู่มือนี้ไม่ครอบคลุมถึงการกำหนดเส้นทาง แต่ครอบคลุมเฉพาะการตอบสนองต่อเหตุการณ์ตามเส้นทาง

ภาพรวม

Navigation SDK สําหรับ iOS มี Listener ที่เชื่อมโยงกับตําแหน่งของผู้ใช้และสภาพเส้นทาง รวมถึงข้อมูลเวลาและระยะทางที่สําคัญ ในแอปของคุณ วีวคอนโทรลเลอร์ของแผนที่ต้องใช้โปรโตคอลสําหรับโปรแกรมฟังเหล่านี้ GMSRoadSnappedLocationProviderListener และ GMSNavigatorListener

รายการนี้แสดงเมธอด Listener ที่พร้อมใช้งานสําหรับเหตุการณ์การนําทาง

  • GMSNavigatorListener.didArriveAtWaypoint ซึ่งจะทริกเกอร์เมื่อถึงปลายทาง
  • GMSNavigatorListener.navigatorDidChangeRoute ซึ่งจะทริกเกอร์เมื่อเส้นทางเปลี่ยนแปลง
  • GMSNavigatorListener.didUpdateRemainingTime ซึ่งเรียกซ้ำๆ เมื่อเวลาถึงจุดหมายถัดไปมีการเปลี่ยนแปลงขณะที่การแนะนำทำงานอยู่
  • GMSNavigatorListener.didUpdateRemainingDistance ซึ่งเรียกซ้ำๆ เมื่อระยะทางไปยังจุดหมายถัดไปเปลี่ยนแปลงขณะที่ระบบนำทางทำงานอยู่
  • GMSNavigatorListener.didUpdateDelayCategory ซึ่งจะเรียกใช้เมื่อหมวดหมู่ความล่าช้าของปลายทางถัดไปมีการเปลี่ยนแปลงขณะที่คำแนะนำทำงานอยู่
  • GMSNavigatorListener.didChangeSuggestedLightingMode ซึ่งจะทริกเกอร์เมื่ออัปเดตสภาพแสงโดยประมาณ เช่น เมื่อตกกลางคืนที่ตำแหน่งปัจจุบันของผู้ใช้ แสงสว่างจะเปลี่ยนไป
  • GMSNavigatorListener.didUpdateSpeedingPercentage ซึ่งจะทริกเกอร์เมื่อคนขับขับรถเร็วเกินขีดจำกัด
  • GMSRoadSnappedLocationProviderListener.didUpdateLocation ซึ่งเรียกซ้ำๆ เมื่อตำแหน่งของผู้ใช้เปลี่ยนแปลง

ดูรหัส

/*
 * Copyright 2020 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import GoogleNavigation
import UIKit

class ViewController: UIViewController,
  GMSNavigatorListener,
  GMSRoadSnappedLocationProviderListener
{

  var mapView: GMSMapView!
  var locationManager: CLLocationManager!

  override func loadView() {

    locationManager = CLLocationManager()

    let camera = GMSCameraPosition.camera(withLatitude: 47.67, longitude: -122.20, zoom: 14)
    mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)

    // Add listeners for GMSNavigator and GMSRoadSnappedLocationProvider.
    mapView.navigator?.add(self)
    mapView.roadSnappedLocationProvider?.add(self)

    // Set the time update threshold (seconds) and distance update threshold (meters).
    mapView.navigator?.timeUpdateThreshold = 10
    mapView.navigator?.distanceUpdateThreshold = 100

    // Show the terms and conditions.
    let companyName = "Ride Sharing Co."
    GMSNavigationServices.showTermsAndConditionsDialogIfNeeded(
      withCompanyName: companyName
    ) { termsAccepted in
      if termsAccepted {
        // Enable navigation if the user accepts the terms.
        self.mapView.isNavigationEnabled = true

        // Request authorization to use location services.
        self.locationManager.requestAlwaysAuthorization()

        // Request authorization for alert notifications which deliver guidance instructions
        // in the background.
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert]) {
          granted, error in
          // Handle denied authorization to display notifications.
          if !granted || error != nil {
            print("Authorization to deliver notifications was rejected.")
          }
        }
      } else {
        // Handle the case when the user rejects the terms and conditions.
      }
    }

    view = mapView

    makeButton()
  }

  // Create a route and start guidance.
  @objc func startNav() {
    var destinations = [GMSNavigationWaypoint]()
    destinations.append(
      GMSNavigationWaypoint.init(
        placeID: "ChIJnUYTpNASkFQR_gSty5kyoUk",
        title: "PCC Natural Market")!)
    destinations.append(
      GMSNavigationWaypoint.init(
        placeID: "ChIJJ326ROcSkFQRBfUzOL2DSbo",
        title: "Marina Park")!)

    mapView.navigator?.setDestinations(destinations) { routeStatus in
      guard routeStatus == .OK else {
        print("Handle route statuses that are not OK.")
        return
      }
      self.mapView.navigator?.isGuidanceActive = true
      self.mapView.cameraMode = .following
      self.mapView.locationSimulator?.simulateLocationsAlongExistingRoute()
    }

    mapView.roadSnappedLocationProvider?.startUpdatingLocation()
  }

  // Listener to handle continuous location updates.
  func locationProvider(
    _ locationProvider: GMSRoadSnappedLocationProvider,
    didUpdate location: CLLocation
  ) {
    print("Location: \(location.description)")
  }

  // Listener to handle speeding events.
  func navigator(
    _ navigator: GMSNavigator, didUpdateSpeedingPercentage percentageAboveLimit: CGFloat
  ) {
    print("Speed is \(percentageAboveLimit) above the limit.")
  }

  // Listener to handle arrival events.
  func navigator(_ navigator: GMSNavigator, didArriveAt waypoint: GMSNavigationWaypoint) {
    print("You have arrived at: \(waypoint.title)")
    mapView.navigator?.continueToNextDestination()
    mapView.navigator?.isGuidanceActive = true
  }

  // Listener for route change events.
  func navigatorDidChangeRoute(_ navigator: GMSNavigator) {
    print("The route has changed.")
  }

  // Listener for time to next destination.
  func navigator(_ navigator: GMSNavigator, didUpdateRemainingTime time: TimeInterval) {
    print("Time to next destination: \(time)")
  }

  // Delegate for distance to next destination.
  func navigator(
    _ navigator: GMSNavigator,
    didUpdateRemainingDistance distance: CLLocationDistance
  ) {
    let miles = distance * 0.00062137
    print("Distance to next destination: \(miles) miles.")
  }

  // Delegate for traffic updates to next destination
  func navigator(
    _ navigator: GMSNavigator,
    didUpdate delayCategory: GMSNavigationDelayCategory
  ) {
    print("Delay category to next destination: \(String(describing: delayCategory)).")
  }

  // Delegate for suggested lighting mode changes.
  func navigator(
    _ navigator: GMSNavigator,
    didChangeSuggestedLightingMode lightingMode: GMSNavigationLightingMode
  ) {
    print("Suggested lighting mode has changed: \(String(describing: lightingMode))")

    // Change to the suggested lighting mode.
    mapView.lightingMode = lightingMode
  }

  // Add a button to the view.
  func makeButton() {
    // Start navigation.
    let navButton = UIButton(frame: CGRect(x: 5, y: 150, width: 200, height: 35))
    navButton.backgroundColor = .blue
    navButton.alpha = 0.5
    navButton.setTitle("Start navigation", for: .normal)
    navButton.addTarget(self, action: #selector(startNav), for: .touchUpInside)
    self.mapView.addSubview(navButton)
  }

}
/*
 * Copyright 2020 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#import "ViewController.h"
@import GoogleNavigation;

@interface ViewController () <GMSNavigatorListener, GMSRoadSnappedLocationProviderListener>

@end

@implementation ViewController {
  GMSMapView *_mapView;
  CLLocationManager *_locationManager;
}

- (void)loadView {

  _locationManager = [[CLLocationManager alloc] init];

  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:47.67
                                                          longitude:-122.20
                                                               zoom:14];
  _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

  // Add listeners for GMSNavigator and GMSRoadSnappedLocationProvider.
  [_mapView.navigator addListener:self];
  [_mapView.roadSnappedLocationProvider addListener:self];

  // Set the time update threshold (seconds) and distance update threshold (meters).
  _mapView.navigator.timeUpdateThreshold = 10;
  _mapView.navigator.distanceUpdateThreshold = 100;

  // Show the terms and conditions.
  NSString *companyName = @"Ride Sharing Co.";
  [GMSNavigationServices
   showTermsAndConditionsDialogIfNeededWithCompanyName:companyName
                                              callback:^(BOOL termsAccepted) {
     if (termsAccepted) {
       // Enable navigation if the user accepts the terms.
       _mapView.navigationEnabled = YES;

       // Request authorization to use location services.
       [_locationManager requestAlwaysAuthorization];

     } else {
       // Handle the case when the user rejects the terms and conditions.
     }
   }];

  self.view = _mapView;

  [self makeButton];
}

// Create a route and initiate navigation.
- (void)startNav {
  NSArray<GMSNavigationWaypoint *> *destinations =
  @[[[GMSNavigationWaypoint alloc] initWithPlaceID:@"ChIJnUYTpNASkFQR_gSty5kyoUk"
                                             title:@"PCC Natural Market"],
    [[GMSNavigationWaypoint alloc] initWithPlaceID:@"ChIJJ326ROcSkFQRBfUzOL2DSbo"
                                             title:@"Marina Park"]];

  [_mapView.navigator setDestinations:destinations
                             callback:^(GMSRouteStatus routeStatus){
                               _mapView.navigator.guidanceActive = YES;
                               _mapView.navigator.sendsBackgroundNotifications = YES;
                               _mapView.cameraMode = GMSNavigationCameraModeFollowing;
                               [_mapView.locationSimulator simulateLocationsAlongExistingRoute];
                             }];

  [_mapView.roadSnappedLocationProvider startUpdatingLocation];
}

#pragma mark - GMSNavigatorListener
// Listener for continuous location updates.
- (void)locationProvider:(GMSRoadSnappedLocationProvider *)locationProvider
      didUpdateLocation:(CLLocation *)location {
  NSLog(@"Location: %@", location.description);
}

// Listener to handle speeding events.
- (void)navigator:(GMSNavigator *)navigator
    didUpdateSpeedingPercentage:(CGFloat)percentageAboveLimit {
  NSLog(@"Speed is %f percent above the limit.", percentageAboveLimit);
}

// Listener to handle arrival events.
- (void)navigator:(GMSNavigator *)navigator didArriveAtWaypoint:(GMSNavigationWaypoint *)waypoint {
  NSLog(@"You have arrived at: %@", waypoint.title);
  [_mapView.navigator continueToNextDestination];
  _mapView.navigator.guidanceActive = YES;
}

// Listener for route change events.
- (void)navigatorDidChangeRoute:(GMSNavigator *)navigator {
  NSLog(@"The route has changed.");
}

// Listener for time to next destination.
- (void)navigator:(GMSNavigator *)navigator didUpdateRemainingTime:(NSTimeInterval)time {
  NSLog(@"Time to next destination: %f", time);
}

// Listener for distance to next destination.
- (void)navigator:(GMSNavigator *)navigator
      didUpdateRemainingDistance:(CLLocationDistance)distance {
  double miles = distance * 0.00062137;
  NSLog(@"%@", [NSString stringWithFormat:@"Distance to next destination: %.2f.", miles]);
}

// Listener for traffic updates for next destination
- (void)navigator:(GMSNavigator *)navigator
    didUpdateDelayCategory:(GMSNavigationDelayCategory)delayCategory {
  NSLog(@"Delay category to next destination: %ld.", delayCategory);
}

// Listener for suggested lighting mode changes.
-(void)navigator:(GMSNavigator *)navigator
      didChangeSuggestedLightingMode:(GMSNavigationLightingMode)lightingMode {
  NSLog(@"Suggested lighting mode has changed: %ld", (long)lightingMode);

  // Change to the suggested lighting mode.
  _mapView.lightingMode = lightingMode;
}

#pragma mark - Programmatic UI elements

// Add a button to the view.
- (void)makeButton {
  // Start navigation.
  UIButton *navButton = [UIButton buttonWithType:UIButtonTypeCustom];
  [navButton addTarget:self
                action:@selector(startNav)
      forControlEvents:UIControlEventTouchUpInside];
  [navButton setTitle:@"Navigate" forState:UIControlStateNormal];
  [navButton setBackgroundColor:[UIColor blueColor]];
  [navButton setAlpha:0.5];
  navButton.frame = CGRectMake(5.0, 150.0, 100.0, 35.0);
  [_mapView addSubview:navButton];
}

@end

การประกาศว่าเป็นไปตามโปรโตคอลที่กำหนด

ก่อนที่จะใช้วิธีการนําทาง เครื่องมือควบคุมดูต้องปฏิบัติตามโปรโตคอลต่อไปนี้

SwiftObjective-C

class ViewController: UIViewController, GMSNavigatorListener,
GMSRoadSnappedLocationProviderListener {

@interface ViewController () <GMSNavigatorListener,
GMSRoadSnappedLocationProviderListener>

@end

หลังจากใช้โปรโตคอลการนำทางแล้ว ให้ตั้งค่า Listener ให้เป็นตัวควบคุมมุมมอง เช่น คุณสามารถเพิ่มโค้ดต่อไปนี้ลงในเมธอด viewDidLoad()

SwiftObjective-C

mapView.navigator?.add(self) mapView.roadSnappedLocationProvider?.add(self)

[_mapView.navigator addListener:self]; [_mapView.roadSnappedLocationProvider
addListener:self];

การรับหรือหยุดการอัปเดตตำแหน่ง

จำเป็นต้องมีการอัปเดตตำแหน่งเพื่อแสดงความคืบหน้าของผู้ใช้บนแผนที่

อินสแตนซ์ location จะแสดงพร็อพเพอร์ตี้ต่อไปนี้

พร็อพเพอร์ตี้สถานที่ตั้ง คำอธิบาย
ระดับความสูง ความสูงปัจจุบัน
coordinate.latitude พิกัดละติจูดปัจจุบันที่จับคู่กับถนน
coordinate.longitude พิกัดลองจิจูดปัจจุบันที่จับคู่กับถนน
หลักสูตร ทิศทางปัจจุบันเป็นองศา
ความเร็ว ความเร็วปัจจุบัน
การประทับเวลา วันที่/เวลาของการอ่านค่าปัจจุบัน

หากต้องการรับการอัปเดตตำแหน่งอย่างต่อเนื่อง ให้เรียกใช้ mapView.roadSnappedLocationProvider.startUpdatingLocation และใช้ GMSRoadSnappedLocationProviderListener เพื่อจัดการเหตุการณ์ didUpdateLocation

ตัวอย่างต่อไปนี้แสดงการเรียก startUpdatingLocation

SwiftObjective-C

mapView.roadSnappedLocationProvider.startUpdatingLocation()

[_mapView.roadSnappedLocationProvider startUpdatingLocation];

โค้ดต่อไปนี้สร้าง GMSRoadSnappedLocationProviderListener ที่จัดการเหตุการณ์ didUpdateLocation

SwiftObjective-C

func locationProvider(_ locationProvider: GMSRoadSnappedLocationProvider,
didUpdate location: CLLocation) { print("Location: \(location.description)") }

-   (void)locationProvider:(GMSRoadSnappedLocationProvider *)locationProvider
    didUpdateLocation:(CLLocation *)location { NSLog(@"Location: %@",
    location.description); }

หากต้องการรับข้อมูลอัปเดตตำแหน่งเมื่อแอปทำงานอยู่เบื้องหลัง ให้ตั้งค่า allowsBackgroundLocationUpdates เป็น "จริง"

SwiftObjective-C

mapView.roadSnappedLocationProvider.allowsBackgroundLocationUpdates = true

 _mapView.roadSnappedLocationProvider.allowsBackgroundLocationUpdates = YES;

การตรวจหาเหตุการณ์การมาถึง

แอปใช้เหตุการณ์ didArriveAtWaypoint เพื่อตรวจหาเมื่อไปถึงปลายทางแล้ว คุณกลับมาใช้การแนะนำต่อและไปยังจุดสังเกตถัดไปได้โดยกด continueToNextDestination() แล้วเปิดใช้การแนะนำอีกครั้ง แอปของคุณต้องเปิดใช้คำแนะนำอีกครั้งหลังจากเรียกใช้ continueToNextDestination()

หลังจากแอปเรียก continueToNextDestination แล้ว โปรแกรมนำทางจะไม่มีข้อมูลเกี่ยวกับปลายทางก่อนหน้าอีกต่อไป หากต้องการวิเคราะห์ข้อมูลเกี่ยวกับช่วงของเส้นทาง คุณต้องเรียกข้อมูลนี้จากโปรแกรมนำทางก่อนเรียกใช้ continueToNextDestination()

ตัวอย่างโค้ดต่อไปนี้แสดงเมธอดในการจัดการเหตุการณ์ didArriveAtWaypoint

SwiftObjective-C

func navigator(_ navigator: GMSNavigator, didArriveAt waypoint:
GMSNavigationWaypoint) { print("You have arrived at: \(waypoint.title)")
mapView.navigator?.continueToNextDestination()
mapView.navigator?.isGuidanceActive = true }

-   (void)navigator:(GMSNavigator *)navigator
    didArriveAtWaypoint:(GMSNavigationWaypoint *)waypoint { NSLog(@"You have
    arrived at: %@", waypoint.title); [_mapView.navigator
    continueToNextDestination]; _mapView.navigator.guidanceActive = YES; }

การรับข้อมูลอัปเดตเกี่ยวกับการเปลี่ยนแปลงเส้นทาง

หากต้องการรับการแจ้งเตือนทุกครั้งที่มีการเปลี่ยนแปลงเส้นทาง ให้สร้างเมธอดเพื่อจัดการเหตุการณ์ navigatorDidChangeRoute คุณสามารถเข้าถึงเส้นทางใหม่ได้โดยใช้พร็อพเพอร์ตี้ routeLegs และ currentRouteLeg ของ GMSNavigator

SwiftObjective-C

func navigatorDidChangeRoute(_ navigator: GMSNavigator) { print("The route has
changed.") }

-   (void)navigatorDidChangeRoute:(GMSNavigator *)navigator { NSLog(@"The route
    has changed."); }

การรับข้อมูลอัปเดตเวลาถึงจุดหมาย

หากต้องการรับการอัปเดตเวลาถึงปลายทางอย่างต่อเนื่อง ให้สร้างเมธอดเพื่อจัดการเหตุการณ์ didUpdateRemainingTime พารามิเตอร์ time จะระบุเวลาโดยประมาณเป็นวินาทีจนกว่าจะถึงปลายทางถัดไป

SwiftObjective-C

func navigator(_ navigator: GMSNavigator, didUpdateRemainingTime time:
TimeInterval) { print("Time to next destination: \(time)") }

-   (void)navigator:(GMSNavigator *)navigator
    didUpdateRemainingTime:(NSTimeInterval)time { NSLog(@"Time to next
    destination: %f", time); }

หากต้องการตั้งค่าการเปลี่ยนแปลงขั้นต่ำของเวลาโดยประมาณในการไปยังปลายทางถัดไป ให้ตั้งค่าพร็อพเพอร์ตี้ timeUpdateThreshold ใน GMSNavigator ค่านี้มีหน่วยเป็นวินาที หากไม่ได้ตั้งค่าพร็อพเพอร์ตี้นี้ บริการจะใช้ค่าเริ่มต้น 1 วินาที

SwiftObjective-C

navigator?.timeUpdateThreshold = 10

navigator.timeUpdateThreshold = 10;

การรับข้อมูลอัปเดตระยะทางไปยังจุดหมาย

หากต้องการรับการอัปเดตระยะทางไปยังปลายทางอย่างต่อเนื่อง ให้สร้างเมธอดเพื่อจัดการเหตุการณ์ didUpdateRemainingDistance พารามิเตอร์ distance จะแสดงระยะทางโดยประมาณไปยังจุดหมายถัดไปเป็นเมตร

SwiftObjective-C

func navigator(_ navigator: GMSNavigator, didUpdateRemainingDistance distance:
CLLocationDistance) { let miles = distance * 0.00062137 print("Distance to next
destination: \(miles) miles.") }

-   (void)navigator:(GMSNavigator *)navigator
    didUpdateRemainingDistance:(CLLocationDistance)distance { double miles =
    distance * 0.00062137; NSLog(@"%@", [NSString stringWithFormat:@"Distance to
    next destination: %.2f.", miles]); }

หากต้องการตั้งค่าการเปลี่ยนแปลงขั้นต่ำของระยะทางโดยประมาณไปยังปลายทางถัดไป ให้ตั้งค่าพร็อพเพอร์ตี้ distanceUpdateThreshold ใน GMSNavigator (ค่าจะระบุเป็นเมตร) หากไม่ได้ตั้งค่าพร็อพเพอร์ตี้นี้ บริการจะใช้ค่าเริ่มต้นเป็น 1 เมตร

SwiftObjective-C

navigator?.distanceUpdateThreshold = 100

navigator.distanceUpdateThreshold = 100;

การรับข้อมูลอัปเดตการจราจร

หากต้องการรับข้อมูลอัปเดตอย่างต่อเนื่องเกี่ยวกับปริมาณการจราจรของเส้นทางที่เหลือ ให้สร้างเมธอดเพื่อจัดการเหตุการณ์ didUpdateDelayCategory การเรียกใช้ delayCategoryToNextDestination จะแสดงผล GMSNavigationDelayCategory ซึ่งมีค่า 0 ถึง 3 การอัปเดตหมวดหมู่จะอิงตามตําแหน่งปัจจุบันของผู้ใช้แอป หากไม่มีข้อมูลการเข้าชม GMSNavigationDelayCategory จะแสดงผลเป็น 0 ตัวเลข 1-3 หมายถึงการไหลที่เพิ่มขึ้นจากเบาไปหนัก

SwiftObjective-C

func navigator(_ navigator: GMSNavigator, didUpdate delayCategory:
GMSNavigationDelayCategory) { print("Traffic flow to next destination:
\(delayCategory)") }

-   (void)navigator:(GMSNavigator *)navigator
    didUpdateDelayCategory:(GMSNavigationDelayCategory)delayCategory {
    NSLog(@"Traffic flow to next destination: %ld", (long)delayCategory); }

พร็อพเพอร์ตี้ GMSNavigationDelayCategory จะแสดงระดับการเลื่อนเวลาต่อไปนี้

หมวดหมู่ความล่าช้า คำอธิบาย
GMSNavigationDelayCategoryNoData 0 - ไม่พร้อมใช้งาน ไม่มีข้อมูลการเข้าชม หรือ
เส้นทาง
GMSNavigationDelayCategoryHeavy 1 - มาก
GMSNavigationDelayCategoryMedium 2 - ปานกลาง
GMSNavigationDelayCategoryLight 3 - ไฟ

การรับข้อมูลอัปเดตเกี่ยวกับการขับรถเร็ว

หากต้องการรับข้อมูลอัปเดตเมื่อคนขับขับรถเร็วเกินขีดจำกัด ให้สร้างเมธอดเพื่อจัดการเหตุการณ์ didUpdateSpeedingPercentage

SwiftObjective-C

// Listener to handle speeding events. func navigator( _ navigator:
GMSNavigator, didUpdateSpeedingPercentage percentageAboveLimit: CGFloat ) {
print("Speed is \(percentageAboveLimit) above the limit.") }

// Listener to handle speeding events. - (void)navigator:(GMSNavigator
*)navigator didUpdateSpeedingPercentage:(CGFloat)percentageAboveLimit {
NSLog(@"Speed is %f percent above the limit.", percentageAboveLimit); }

การเปลี่ยนโหมดแสงที่แนะนำ

หากต้องการรับข้อมูลอัปเดตเกี่ยวกับการเปลี่ยนแปลงแสงโดยประมาณ ให้สร้างเมธอดเพื่อจัดการเหตุการณ์ didChangeSuggestedLightingMode

SwiftObjective-C

// Define a listener for suggested changes to lighting mode. func navigator(_
navigator: GMSNavigator, didChangeSuggestedLightingMode lightingMode:
GMSNavigationLightingMode) { print("Suggested lighting mode has changed:
\(String(describing: lightingMode))")

 // Make the suggested change. mapView.lightingMode = lightingMode }

// Define a listener for suggested changes to lighting mode.
-(void)navigator:(GMSNavigator *)navigator didChangeSuggestedLightingMode:
(GMSNavigationLightingMode)lightingMode { NSLog(@"Suggested lighting mode has
changed: %ld", (long)lightingMode);

 // Make the suggested change. _mapView.lightingMode = lightingMode; }