একটি রুট নেভিগেট করুন

iOS-এর জন্য নেভিগেশন SDK ব্যবহার করে আপনার অ্যাপের মধ্যে একটি গন্তব্যে যাওয়ার জন্য একটি রুট প্লট করতে এই নির্দেশিকা অনুসরণ করুন।

ওভারভিউ

  1. আপনার অ্যাপে নেভিগেশন SDK সংহত করুন, যেমন আপনার প্রকল্প সেট আপ বিভাগে বর্ণিত হয়েছে।
  2. একটি GMSMapView কনফিগার করুন।
  3. ব্যবহারকারীকে শর্তাবলী মেনে নিতে এবং অবস্থান পরিষেবা এবং ব্যাকগ্রাউন্ড বিজ্ঞপ্তিগুলি অনুমোদন করার জন্য অনুরোধ করুন৷
  4. এক বা একাধিক গন্তব্য সমন্বিত একটি অ্যারে তৈরি করুন।
  5. টার্ন-বাই-টার্ন নেভিগেশন নিয়ন্ত্রণ করতে একটি GMSNavigator সংজ্ঞায়িত করুন।

    • setDestinations ব্যবহার করে গন্তব্য যোগ করুন।
    • নেভিগেশন শুরু করতে isGuidanceActive true সেট করুন।
    • আপনার অ্যাপ পরীক্ষা, ডিবাগিং এবং প্রদর্শনের জন্য রুট বরাবর গাড়ির অগ্রগতি অনুকরণ করতে simulateLocationsAlongExistingRoute ব্যবহার করুন।

কোড দেখুন

/*
 * Copyright 2017 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 {

  var mapView: GMSMapView!
  var locationManager: CLLocationManager!

  override func loadView() {

    locationManager = CLLocationManager()

    // Set up the map view.
    let camera = GMSCameraPosition.camera(withLatitude: 47.67, longitude: -122.20, zoom: 14)
    mapView = GMSMapView.map(withFrame: .zero, camera: camera)

    // 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
        self.mapView.settings.compassButton = 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("User rejected request to display notifications.")
          }
        }
      } else {
        // Handle rejection of terms and conditions.
      }
    }

    view = mapView

    makeButton()
  }

  // Create a route and start guidance.
  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.locationSimulator?.simulateLocationsAlongExistingRoute()
      self.mapView.cameraMode = .following
    }
  }

  // Add a button to the view.
  func makeButton() {
    // A button to 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 2017 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 ()
@end

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

- (void)loadView {

  _locationManager = [[CLLocationManager alloc] init];

  // Set up the map view.
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:47.67
                                                          longitude:-122.20
                                                               zoom:14];
  _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

  // 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;
       _mapView.settings.compassButton = YES;

       // Request authorization to use the current device location.
       [_locationManager requestAlwaysAuthorization];

       // Request authorization for alert notifications which deliver guidance instructions
       // in the background.
       UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
       UNAuthorizationOptions options = UNAuthorizationOptionAlert;
       [center requestAuthorizationWithOptions:options
                             completionHandler:^(BOOL granted, NSError *_Nullable error) {
                               if (!error && granted) {
                                 NSLog(@"iOS Notification Permission: newly Granted");
                               } else {
                                 NSLog(@"iOS Notification Permission: Failed or Denied");
                               }
                             }];
     } else {
       // Handle rejection of 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.locationSimulator simulateLocationsAlongExistingRoute];
                               _mapView.navigator.guidanceActive = YES;
                               _mapView.navigator.sendsBackgroundNotifications = YES;
                               _mapView.cameraMode = GMSNavigationCameraModeFollowing;
                             }];
}

// Add a button to the view.
- (void)makeButton {
  // A button to 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.frame = CGRectMake(5.0, 150.0, 100.0, 35.0);
  [_mapView addSubview:navButton];
}

@end

প্রয়োজনীয় অনুমোদনের জন্য ব্যবহারকারীকে অনুরোধ করুন

নেভিগেশন SDK ব্যবহার করার আগে, ব্যবহারকারীকে অবশ্যই শর্তাবলীর সাথে সম্মত হতে হবে এবং অবস্থান পরিষেবাগুলির ব্যবহার অনুমোদন করতে হবে, যা নেভিগেশনের জন্য প্রয়োজনীয়৷ যদি আপনার অ্যাপটি ব্যাকগ্রাউন্ডে চলে, তবে এটি অবশ্যই ব্যবহারকারীকে নির্দেশিকা সতর্কতা বিজ্ঞপ্তি অনুমোদন করার জন্য অনুরোধ করবে। এই বিভাগটি দেখায় কিভাবে প্রয়োজনীয় অনুমোদন প্রম্পট প্রদর্শন করতে হয়।

অবস্থান সেবা অনুমোদন

নেভিগেশন SDK অবস্থান পরিষেবা ব্যবহার করে, যার জন্য ব্যবহারকারীর অনুমোদন প্রয়োজন৷ অবস্থান পরিষেবাগুলি সক্ষম করতে এবং অনুমোদন ডায়ালগ প্রদর্শন করতে, এই পদক্ষেপগুলি নিন:

  1. Info.plistNSLocationAlwaysUsageDescription কী যোগ করুন।
  2. মানটির জন্য, কেন আপনার অ্যাপের লোকেশন পরিষেবার প্রয়োজন তার একটি সংক্ষিপ্ত ব্যাখ্যা যোগ করুন। উদাহরণস্বরূপ: "এই অ্যাপটিকে পালাক্রমে নেভিগেশনের জন্য অবস্থান পরিষেবাগুলি ব্যবহার করার অনুমতি প্রয়োজন।"

  3. অনুমোদন ডায়ালগ প্রদর্শন করতে, অবস্থান ব্যবস্থাপকের উদাহরণের requestAlwaysAuthorization() এ কল করুন।

self.locationManager.requestAlwaysAuthorization()

[_locationManager requestAlwaysAuthorization];

পটভূমি নির্দেশিকা জন্য সতর্কতা বিজ্ঞপ্তি অনুমোদন

অ্যাপ্লিকেশানটি ব্যাকগ্রাউন্ডে চলাকালীন সতর্কতা বিজ্ঞপ্তি প্রদান করার জন্য নেভিগেশন SDK-এর ব্যবহারকারীর অনুমতির প্রয়োজন৷ এই বিজ্ঞপ্তিগুলি প্রদর্শনের অনুমতির জন্য ব্যবহারকারীকে অনুরোধ করতে নিম্নলিখিত কোড যোগ করুন:

UNUserNotificationCenter.current().requestAuthorization(options: [.alert]) {
  granted, error in
    // Handle denied authorization to display notifications.
    if !granted || error != nil {
      print("User rejected request to display notifications.")
    }
}

// Request authorization for alert notifications.
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNAuthorizationOptions options = UNAuthorizationOptionAlert;
[center requestAuthorizationWithOptions:options
                      completionHandler:
 ^(
   BOOL granted,
   NSError *_Nullable error) {
     if (!error && granted) {
       NSLog(@"iOS Notification Permission: newly Granted");
     } else {
       NSLog(@"iOS Notification Permission: Failed or Denied");
     }
   }];

শর্তাবলী গ্রহণ করুন

শর্তাবলী এবং শর্তাবলী ডায়ালগ দেখাতে নিম্নলিখিত কোড ব্যবহার করুন, এবং ব্যবহারকারী যখন শর্তাদি স্বীকার করেন তখন নেভিগেশন সক্ষম করুন৷ মনে রাখবেন যে এই উদাহরণে অবস্থান পরিষেবা এবং নির্দেশিকা সতর্কতা বিজ্ঞপ্তিগুলির কোড অন্তর্ভুক্ত রয়েছে (আগে দেখানো হয়েছে)৷

  let termsAndConditionsOptions = GMSNavigationTermsAndConditionsOptions(companyName: "Ride Sharing Co.")

  GMSNavigationServices.showTermsAndConditionsDialogIfNeeded(
    with: termsAndConditionsOptions) { termsAccepted in
    if termsAccepted {
      // Enable navigation if the user accepts the terms.
      self.mapView.isNavigationEnabled = true
      self.mapView.settings.compassButton = 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 rejection of notification authorization.
        if !granted || error != nil {
          print("Authorization to deliver notifications was rejected.")
        }
      }
    } else {
      // Handle rejection of terms and conditions.
    }
  }

GMSNavigationTermsAndConditionsOptions *termsAndConditionsOptions = [[GMSNavigationTermsAndConditionsOptions alloc] initWithCompanyName:@"Ride Sharing Co."];

[GMSNavigationServices
  showTermsAndConditionsDialogIfNeededWithOptions:termsAndConditionsOptions
  callback:^(BOOL termsAccepted) {
   if (termsAccepted) {
     // Enable navigation if the user accepts the terms.
     _mapView.navigationEnabled = YES;
     _mapView.settings.compassButton = YES;

     // Request authorization to use the current device location.
     [_locationManager requestAlwaysAuthorization];

     // Request authorization for alert notifications which deliver guidance instructions
     // in the background.
     UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
     UNAuthorizationOptions options = UNAuthorizationOptionAlert;
     [center requestAuthorizationWithOptions:options
                           completionHandler:
     ^(
       BOOL granted,
       NSError *_Nullable error) {
         if (!error && granted) {
           NSLog(@"iOS Notification Permission: newly Granted");
         } else {
           NSLog(@"iOS Notification Permission: Failed or Denied");
         }
       }];
   } else {
     // Handle rejection of the terms and conditions.
   }
 }];

একটি রুট তৈরি করুন এবং নির্দেশিকা শুরু করুন

একটি রুট প্লট করতে, পরিদর্শনের জন্য এক বা একাধিক গন্তব্য ( GMSNavigationWaypoint ) সম্বলিত একটি অ্যারে সহ ন্যাভিগেটরের setDestinations() পদ্ধতিতে কল করুন। সফলভাবে গণনা করা হলে, রুটটি মানচিত্রে দেখানো হয়। রুট বরাবর নির্দেশিকা শুরু করতে, প্রথম গন্তব্য থেকে শুরু করে, কলব্যাকে isGuidanceActive true সেট করুন।

নিম্নলিখিত উদাহরণ দেখায়:

  • দুটি গন্তব্য নিয়ে একটি নতুন রুট তৈরি করা হচ্ছে।
  • নির্দেশিকা শুরু।
  • পটভূমি নির্দেশিকা বিজ্ঞপ্তি সক্রিয় করা হচ্ছে.
  • রুট বরাবর ভ্রমণ অনুকরণ (ঐচ্ছিক)।
  • ক্যামেরা মোড সেট করা হচ্ছে "অনুসরণ করুন" (ঐচ্ছিক)।

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
    self.mapView.navigator?.isGuidanceActive = true
    self.mapView.locationSimulator?.simulateLocationsAlongExistingRoute()
    self.mapView.cameraMode = .following
  }
}

- (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.locationSimulator simulateLocationsAlongExistingRoute];
                               _mapView.navigator.guidanceActive = YES;
                               _mapView.cameraMode = GMSNavigationCameraModeFollowing;
                             }];
}

প্লেস আইডি সম্পর্কে জানতে অনুগ্রহ করে প্লেস আইডি পড়ুন।

ভ্রমণ মোড সেট করুন

ভ্রমণ মোড নির্ধারণ করে যে কোন ধরনের রুট আনা হবে এবং ব্যবহারকারীর পথ নির্ধারণ করা হবে। আপনি একটি রুটের জন্য চারটি ভ্রমণ মোডের মধ্যে একটি সেট করতে পারেন: ড্রাইভিং, সাইকেল চালানো, হাঁটা এবং ট্যাক্সি। ড্রাইভিং এবং ট্যাক্সি মোডে, ব্যবহারকারীর কোর্স ভ্রমণের দিকনির্দেশের উপর ভিত্তি করে; সাইকেল চালানো এবং হাঁটা মোডে কোর্সটি ডিভাইসটি যে দিকে মুখ করছে তার দ্বারা প্রতিনিধিত্ব করা হয়।

মানচিত্র দর্শনের travelMode বৈশিষ্ট্য সেট করুন, যেমনটি নিম্নলিখিত উদাহরণে দেখানো হয়েছে:

self.mapView.travelMode = .cycling

_mapView.travelMode = GMSNavigationTravelModeCycling;

এড়ানোর জন্য রাস্তা সেট করুন

একটি রুট বরাবর হাইওয়ে এবং/অথবা টোল রাস্তাগুলি এড়াতে এড়িয়ে avoidsHighways এবং avoidsTolls BOOL বৈশিষ্ট্যগুলি ব্যবহার করুন৷

self.mapView.navigator?.avoidsTolls = true

_mapView.navigator.avoidsTolls = YES;

প্লেসআইডি ফাইন্ডার

আপনি রুট গন্তব্যের জন্য ব্যবহার করার জন্য স্থান আইডি খুঁজতে PlaceID ফাইন্ডার ব্যবহার করতে পারেন। GMSNavigationWaypoint এর সাথে একটি placeID থেকে একটি গন্তব্য যোগ করুন।

ভাসমান পাঠ্য

আপনি আপনার অ্যাপের যেকোনো জায়গায় ভাসমান পাঠ্য যোগ করতে পারেন, যতক্ষণ না Google অ্যাট্রিবিউশন কভার করা হয়। ন্যাভিগেশন SDK মানচিত্রের অক্ষাংশ/দ্রাঘিমাংশে বা লেবেলে পাঠ্যকে অ্যাঙ্করিং সমর্থন করে না। আরও তথ্যের জন্য, তথ্য উইন্ডো দেখুন।