रास्ते की जानकारी पाएं

इस गाइड का पालन करके अपना ऐप्लिकेशन सेट अप करें और मौजूदा रूट के लिए समय, दूरी, और रूट की जानकारी पाएं.

खास जानकारी

मौजूदा रास्ते के बारे में जानकारी पाने के लिए, navigator इंस्टेंस से सही प्रॉपर्टी लें:

  • GMSNavigator.timeToNextDestination का इस्तेमाल करके, मौजूदा रास्ते पर अगली मंज़िल तक पहुंचने का अनुमानित समय सेकंड में बताया जा सकता है.
  • GMSNavigator.distanceToNextDestination मौजूदा रास्ते पर अगली मंज़िल की दूरी मीटर में जानने के लिए.
  • GMSNavigationDelayCategory का इस्तेमाल करके ट्रैफ़िक के फ़्लो की देरी की कैटगरी देखी जा सकती है.
  • GMSNavigator.currentRouteLeg यहां क्लिक करें.
  • GMSNavigator.traveledPath पर क्लिक करें.

कोड देखें

अगली मंज़िल पर पहुंचने में लगने वाला समय लोड हो रहा है

अगली मंज़िल का समय जानने के लिए, timeToNextDestination() पर कॉल करें. यह NSTimeInterval वैल्यू दिखाता है. इस उदाहरण में दिखाया गया है कि अगले डेस्टिनेशन पर जाने में कितना समय लगेगा:

Swift

if let navigator = mapView.navigator {
  let time = navigator.timeToNextDestination
  let minutes = floor(time/60)
  let seconds = round(time - minutes * 60)
  NSLog("Time to next destination: %.0f:%.0f", minutes, seconds)
}

Objective-C

NSTimeInterval time = _mapView.navigator.timeToNextDestination;
int minutes = floor(time/60);
int seconds = round(time - minutes * 60);
NSLog(@"%@", [NSString stringWithFormat:@"Time to next destination: %i:%i.", minutes, seconds]);

अगली मंज़िल की दूरी लोड की जा रही है

अगली मंज़िल की दूरी जानने के लिए, distanceToNextDestination() पर कॉल करें. यह CLLocationDistance वैल्यू दिखाता है. इकाइयां मीटर में दी गई हैं.

Swift

if let navigator = mapView.navigator {
  let distance = navigator.distanceToNextDestination
  let miles = distance * 0.00062137
  NSLog("Distance to next destination: %.2f miles.", miles)
}

Objective-C

CLLocationDistance distance = _mapView.navigator.distanceToNextDestination;
double miles = distance * 0.00062137;
NSLog(@"%@", [NSString stringWithFormat:@"Distance to next destination: %.2f.", miles]);

अगली मंज़िल के लिए ट्रैफ़िक का हाल जाना जा रहा है

अगले डेस्टिनेशन के ट्रैफ़िक के फ़्लो को दिखाने वाली वैल्यू पाने के लिए, delayCategoryToNextDestination पर कॉल करें. यह पैरामीटर GMSNavigationDelayCategory दिखाता है. यहां दिए गए उदाहरण में, नतीजे का आकलन करने और ट्रैफ़िक मैसेज को लॉग करने का तरीका बताया गया है:

Swift

if let navigator = mapView.navigator {
  // insert sample for evaluating traffic value
  let delay = navigator.delayCategoryToNextDestination
  let traffic = "unavailable"
  switch delay {
    case .noData:
      traffic = "unavailable"
    case .heavy:
      traffic = "heavy"
    case .medium:
      traffic = "moderate"
    case .light:
      traffic = "light"
    default:
      traffic = "unavailable"
  }
  print("Traffic is \(traffic).")
}

Objective-C

GMSNavigationDelayCategory delay = mapView.navigator.delayCategoryToNextDestination;
NSString *traffic = @"";

switch (delayCategory) {
    case GMSNavigationDelayCategoryNoData:
      traffic = @"No Data";
      break;
    case GMSNavigationDelayCategoryHeavy:
      traffic = @"Heavy";
      break;
    case GMSNavigationDelayCategoryMedium:
      traffic = @"Medium";
      break;
    case GMSNavigationDelayCategoryLight:
      traffic = @"Light";
      break;
    default:
      NSLog(@"Invalid delay category: %zd", delayCategory);
 }

NSLog(@"%@", [NSString stringWithFormat:@"Traffic is %@.", traffic]);

मौजूदा पैर के बारे में जानकारी ली जा रही है

रास्ते की मौजूदा मंज़िल के बारे में जानकारी पाने के लिए, currentRouteLeg पर कॉल करें. यह एक GMSRouteLeg इंस्टेंस लौटाता है, जिससे आपको यह जानकारी मिल सकती है:

  • टांग के लिए मंज़िल.
  • पैर में आखिरी कोऑर्डिनेट.
  • वह पथ जिसमें निर्देशांक होते हैं और जिनसे रूट लेग बनता है.

नीचे दिए गए उदाहरण में, अगले रास्ते के लिए टाइटल और अक्षांश/देशांतर निर्देशांक लॉग करने के बारे में बताया गया है:

Swift

if let navigator = mapView.navigator {
  let currentLeg = navigator.currentRouteLeg
  let nextDestination = currentLeg?.destinationWaypoint?.title
  let lat = currentLeg?.destinationCoordinate.latitude.description
  let lng = currentLeg?.destinationCoordinate.longitude.description
  NSLog(nextDestination! + ", " + lat! + "/" + lng!)
}

Objective-C

GMSRouteLeg *currentSegment = _mapView.navigator.currentRouteLeg;
NSString *nextDestination = currentSegment.destinationWaypoint.title;
CLLocationDegrees lat = currentSegment.destinationCoordinate.latitude;
CLLocationDegrees lng = currentSegment.destinationCoordinate.longitude;
NSLog(@"%@", [NSString stringWithFormat:@"%@, %f/%f", nextDestination, lat, lng]);

सबसे हाल में तय किया गया रास्ता पाना

हाल ही में तय की गई यात्रा का रास्ता पाने के लिए, traveledPath पर कॉल करें. इससे एक GMSPath इंस्टेंस दिखता है, जिसे ग़ैर-ज़रूरी पॉइंट को हटाने के लिए आसान बनाया गया है. उदाहरण के लिए, लगातार आने वाले कोलीनियर पॉइंट को एक लाइन सेगमेंट में बदलना. दिशा-निर्देश शुरू होने तक, यह पाथ खाली रहेगा. नीचे दिए गए उदाहरण में, सबसे हाल में की गई यात्रा के लिए सबसे सही रास्ते की जानकारी दी गई है:

Swift

if let navigator = mapView.navigator {
  let latestPath = navigator.traveledPath
  if latestPath.count() > 0 {
    let begin: CLLocationCoordinate2D = latestPath.coordinate(at: 0)
    let current: CLLocationCoordinate2D = latestPath.coordinate(at: latestPath.count() - 1)
    print("Path from (\(begin.latitude),\(begin.longitude)) to (\(current.latitude),\(current.longitude))")
  }
}

Objective-C

GMSPath *latestPath = mapView.navigator.traveledPath;
if (latestPath.count > 0) {
  CLLocationCoordinate2D begin = [latestPath coordinateAtIndex:0];
  CLLocationCoordinate2D current = [latestPath coordinateAtIndex:latestPath.count - 1];
  NSLog(@"Path from %f/%f to %f/%f",
        begin.latitude,
        begin.longitude,
        current.latitude,
        current.longitude);
}