রুট API ক্লায়েন্ট লাইব্রেরি

এই পৃষ্ঠাটি দেখায় কিভাবে রুট API-এর জন্য ক্লায়েন্ট লাইব্রেরি দিয়ে শুরু করতে হয়।

ব্যাখ্যা করা ক্লায়েন্ট লাইব্রেরিতে ক্লায়েন্ট লাইব্রেরি সম্পর্কে আরও পড়ুন।

ক্লায়েন্ট লাইব্রেরি ইনস্টল করা হচ্ছে

জাভা

আরও তথ্যের জন্য, জাভা ডেভেলপমেন্ট এনভায়রনমেন্ট সেট আপ করা দেখুন।

ইনস্টলেশন নির্দেশাবলীর জন্য Java এর জন্য Google Routes API ক্লায়েন্ট দেখুন।

যাওয়া

go get cloud.google.com/go/maps
আরও তথ্যের জন্য, একটি গো ডেভেলপমেন্ট এনভায়রনমেন্ট সেট আপ করা দেখুন।

ইনস্টলেশন নির্দেশাবলীর জন্য Go-এর জন্য Google Routes API ক্লায়েন্ট দেখুন।

Node.js

npm install @googlemaps/routing
আরও তথ্যের জন্য, একটি Node.js ডেভেলপমেন্ট এনভায়রনমেন্ট সেট আপ করা দেখুন।

সম্পূর্ণ ইনস্টলেশন নির্দেশাবলীর জন্য, Node.js-এর জন্য Google Routes API ক্লায়েন্ট দেখুন

পাইথন

আরও তথ্যের জন্য, পাইথন ডেভেলপমেন্ট এনভায়রনমেন্ট সেট আপ করা দেখুন।

সম্পূর্ণ ইনস্টলেশন নির্দেশাবলীর জন্য, পাইথনের জন্য Google Routes API ক্লায়েন্ট দেখুন

.নেট

আরও তথ্যের জন্য, একটি .নেট ডেভেলপমেন্ট এনভায়রনমেন্ট সেট আপ করা দেখুন।

সম্পূর্ণ ইনস্টলেশন নির্দেশাবলীর জন্য, .Net-এর জন্য Google Routes API ক্লায়েন্ট দেখুন

প্রমাণীকরণ সেট আপ করা হচ্ছে

আপনি যখন ক্লায়েন্ট লাইব্রেরি ব্যবহার করেন, আপনি প্রমাণীকরণের জন্য অ্যাপ্লিকেশন ডিফল্ট শংসাপত্র (ADC) ব্যবহার করেন। ADC সেট আপ সম্পর্কে তথ্যের জন্য, অ্যাপ্লিকেশন ডিফল্ট শংসাপত্রের জন্য প্রমাণপত্র সরবরাহ করুন দেখুন। ক্লায়েন্ট লাইব্রেরির সাথে ADC ব্যবহার সম্পর্কে তথ্যের জন্য, ক্লায়েন্ট লাইব্রেরি ব্যবহার করে প্রমাণীকরণ দেখুন।

ক্লায়েন্ট লাইব্রেরি ব্যবহার করে

জাভা

কম্পিউট রুট উদাহরণ:

import com.google.maps.routing.v2.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
   
public class Main {
  public static void main(String[] arguments) throws IOException {
      RoutesSettings routesSettings = RoutesSettings.newBuilder()
              .setHeaderProvider(() -> {
                  Map<String, String> headers = new HashMap<>();
                  headers.put("X-Goog-FieldMask", "*");
                  return headers;
              }).build();
      RoutesClient routesClient = RoutesClient.create(routesSettings);
       
      ComputeRoutesResponse response = routesClient.computeRoutes(ComputeRoutesRequest.newBuilder()
              .setOrigin(Waypoint.newBuilder().setPlaceId("ChIJeRpOeF67j4AR9ydy_PIzPuM").build())
              .setDestination(Waypoint.newBuilder().setPlaceId("ChIJG3kh4hq6j4AR_XuFQnV0_t8").build())
              .setRoutingPreference(RoutingPreference.TRAFFIC_AWARE)
              .setTravelMode(RouteTravelMode.DRIVE).build());
      System.out.println("Response: " + response.toString());
  }
}

রুট ম্যাট্রিক্স উদাহরণ:

import com.google.api.gax.rpc.ServerStream;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.maps.routing.v2.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
   
public class Main {
  public static void main(String[] arguments) throws IOException {
      RoutesSettings routesSettings = RoutesSettings.newBuilder()
              .setHeaderProvider(() -> {
                  Map<String, String> headers = new HashMap<>();
                  headers.put("X-Goog-FieldMask", "*");
                  return headers;
              }).build();
      RoutesClient routesClient = RoutesClient.create(routesSettings);
       
      ServerStreamingCallable<ComputeRouteMatrixRequest, RouteMatrixElement> computeRouteMatrix = routesClient.computeRouteMatrixCallable();
      ServerStream<RouteMatrixElement> stream = computeRouteMatrix.call(ComputeRouteMatrixRequest.newBuilder()
              .addOrigins(RouteMatrixOrigin.newBuilder()
                      .setWaypoint(Waypoint.newBuilder().
                              setPlaceId("ChIJeRpOeF67j4AR9ydy_PIzPuM").build()))
              .addDestinations(RouteMatrixDestination.newBuilder()
                      .setWaypoint(Waypoint.newBuilder().setPlaceId("ChIJG3kh4hq6j4AR_XuFQnV0_t8").build())
                      .build()).setTravelMode(RouteTravelMode.DRIVE)
              .build());
      for (RouteMatrixElement element : stream) {
          System.out.println("Response : " + element.toString());
      }
  }
}

যাওয়া

কম্পিউট রুট উদাহরণ:

import (
  "context"
  "fmt"
  "io"
  "os"
     
  routing "cloud.google.com/go/maps/routing/apiv2"
  "cloud.google.com/go/maps/routing/apiv2/routingpb"
  "google.golang.org/grpc/metadata"
)
   
func main() {
  ctx := context.Background()
  client, err := routing.NewRoutesClient(ctx)
  if err != nil {
    fmt.Fprintf(os.Stderr, "error: %v\n", err)
    os.Exit(1)
  }
     
  computeRoutesReq := routingpb.ComputeRoutesRequest{
    Origin: &routingpb.Waypoint{
      LocationType: &routingpb.Waypoint_PlaceId{
        PlaceId: "ChIJeRpOeF67j4AR9ydy_PIzPuM",
      },
    },
    Destination: &routingpb.Waypoint{
      LocationType: &routingpb.Waypoint_PlaceId{
        PlaceId: "ChIJG3kh4hq6j4AR_XuFQnV0_t8",
      },
    },
    RoutingPreference: routingpb.RoutingPreference_TRAFFIC_AWARE,
    TravelMode:        routingpb.RouteTravelMode_DRIVE,
  }
  ctx = metadata.AppendToOutgoingContext(ctx, "X-Goog-FieldMask", "*")
  computeRoutesResponse, err := client.ComputeRoutes(ctx, &computeRoutesReq)
  if err != nil {
    fmt.Fprintf(os.Stderr, "error: %v\n", err)
    os.Exit(1)
  }
  fmt.Fprintf(os.Stdout, "response: %v\n", computeRoutesResponse)
}

রুট ম্যাট্রিক্স উদাহরণ:

import (
  "context"
  "fmt"
  "io"
  "os"
     
  routing "cloud.google.com/go/maps/routing/apiv2"
  "cloud.google.com/go/maps/routing/apiv2/routingpb"
  "google.golang.org/grpc/metadata"
)
   
func main() {
  ctx := context.Background()
  client, err := routing.NewRoutesClient(ctx)
  if err != nil {
    fmt.Printf("error: %v\n", err)
    os.Exit(1)
  }
     
  computeRouteMatrixReq := routingpb.ComputeRouteMatrixRequest{
    Origins: []*routingpb.RouteMatrixOrigin{
      {
        Waypoint: &routingpb.Waypoint{
          LocationType: &routingpb.Waypoint_PlaceId{
            PlaceId: "ChIJeRpOeF67j4AR9ydy_PIzPuM",
          },
        },
      },
    },
    Destinations: []*routingpb.RouteMatrixDestination{
      {
        Waypoint: &routingpb.Waypoint{
          LocationType: &routingpb.Waypoint_PlaceId{
            PlaceId: "ChIJG3kh4hq6j4AR_XuFQnV0_t8",
          },
        },
      },
    },
    TravelMode: routingpb.RouteTravelMode_DRIVE,
  }
  ctx = metadata.AppendToOutgoingContext(ctx, "X-Goog-FieldMask", "*")
  stream, err := client.ComputeRouteMatrix(ctx, &computeRouteMatrixReq)
  if err != nil {
    fmt.Fprintf(os.Stderr, "error: %v\n", err)
    os.Exit(1)
  }
  for {
    element, err := stream.Recv()
    if err == io.EOF {
      break
    }
    if err != nil {
      fmt.Fprintf(os.Stderr, "error: %v\n", err)
      os.Exit(1)
    }
    fmt.Fprintf(os.Stdout, "element: %v\n", element)
  }
}

Node.js

কম্পিউট রুট উদাহরণ:

// Imports the Routing library
const { RoutesClient } = require("@googlemaps/routing").v2;
const origin = {
  location: {
    latLng: {
      latitude: 37.419734,
      longitude: -122.0827784,
    },
  },
};
const destination = {
  location: {
    latLng: {
      latitude: 37.41767,
      longitude: -122.079595,
    },
  },
};
// Instantiates a client
const routingClient = new RoutesClient();
async function callComputeRoutes() {
  const request = {
    origin,
    destination,
  };
  // Run request
  const response = await routingClient.computeRoutes(request, {
    otherArgs: {
      headers: {
        "X-Goog-FieldMask":
          "routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline",
      },
    },
  });
  console.log(response);
}
callComputeRoutes();

কম্পিউট রুট ম্যাট্রিক্স উদাহরণ:

// Imports the Routing library
const { RoutesClient } = require("@googlemaps/routing").v2;
const origins = [
  {
    waypoint: {
      location: {
        latLng: {
          latitude: 37.420761,
          longitude: -122.081356,
        },
      },
    },
  },
  {
    waypoint: {
      location: {
        latLng: {
          latitude: 37.403184,
          longitude: -122.097371,
        },
      },
    },
  },
];
const destinations = [
  {
    waypoint: {
      location: {
        latLng: {
          latitude: 37.420999,
          longitude: -122.086894,
        },
      },
    },
  },
  {
    waypoint: {
      location: {
        latLng: {
          latitude: 37.383047,
          longitude: -122.044651,
        },
      },
    },
  },
];
// Instantiates a client
const routingClient = new RoutesClient();
async function callComputeRouteMatrix() {
  // Construct request
  const request = {
    origins,
    destinations,
  };
  // Run request
  const stream = await routingClient.computeRouteMatrix(request, {
    otherArgs: {
      headers: {
        "X-Goog-FieldMask": "*",
      },
    },
  });
  stream.on("data", (response) => {
    console.log(response);
  });
  stream.on("error", (err) => {
    throw err;
  });
  stream.on("end", () => {
    /* API call completed */
  });
}
callComputeRouteMatrix();

পাইথন

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.maps import routing_v2


async def sample_compute_routes():
    # Create a client
    client = routing_v2.RoutesAsyncClient()

    # Initialize request argument(s)
    request = routing_v2.ComputeRoutesRequest(
    )

    # Make the request
    response = await client.compute_routes(request=request)

    # Handle the response
    print(response)

.নেট

using Google.Maps.Routing.V2;
using Google.Protobuf.WellKnownTypes;
using System.Threading.Tasks;

public sealed partial class GeneratedRoutesClientSnippets
{
    /// <summary>Snippet for ComputeRoutesAsync</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public async Task ComputeRoutesRequestObjectAsync()
    {
        // Create client
        RoutesClient routesClient = await RoutesClient.CreateAsync();
        // Initialize request argument(s)
        ComputeRoutesRequest request = new ComputeRoutesRequest
        {
            Origin = new Waypoint(),
            Destination = new Waypoint(),
            Intermediates = { new Waypoint(), },
            TravelMode = RouteTravelMode.TravelModeUnspecified,
            RoutingPreference = RoutingPreference.Unspecified,
            PolylineQuality = PolylineQuality.Unspecified,
            DepartureTime = new Timestamp(),
            ComputeAlternativeRoutes = false,
            RouteModifiers = new RouteModifiers(),
            LanguageCode = "",
            Units = Units.Unspecified,
            PolylineEncoding = PolylineEncoding.Unspecified,
            OptimizeWaypointOrder = false,
            RequestedReferenceRoutes =
            {
                ComputeRoutesRequest.Types.ReferenceRoute.Unspecified,
            },
            ExtraComputations =
            {
                ComputeRoutesRequest.Types.ExtraComputation.Unspecified,
            },
            RegionCode = "",
            TrafficModel = TrafficModel.Unspecified,
            ArrivalTime = new Timestamp(),
            TransitPreferences = new TransitPreferences(),
        };
        // Make the request
        ComputeRoutesResponse response = await routesClient.ComputeRoutesAsync(request);
    }
}

অতিরিক্ত সম্পদ