রাউটিং সারাংশ গণনা করুন

রেসপন্সের প্রতিটি স্থানের ভ্রমণের সময়কাল ও দূরত্ব গণনা করতে টেক্সট সার্চ (নতুন) বা নিয়ারবাই সার্চ (নতুন) ব্যবহার করুন:

  1. অনুরোধে RoutingParameters প্যারামিটারটি পাস করুন এবং রাউটিং অরিজিনের অক্ষাংশ ও দ্রাঘিমাংশ স্থানাঙ্ক নির্দিষ্ট করতে setOrigin() ব্যবহার করুন। প্রতিক্রিয়ার প্রতিটি স্থানের সময়কাল এবং দূরত্ব গণনা করার জন্য এই প্যারামিটারটি প্রয়োজন।

  2. রিকোয়েস্ট অবজেক্ট তৈরি করার সময় .setRoutingSummariesIncluded(true) যোগ করুন।

নিম্নলিখিত অনুরোধে, আপনি টেক্সট সার্চ (নতুন) প্রতিক্রিয়ার প্রতিটি স্থানের ভ্রমণের সময়কাল এবং দূরত্ব গণনা করেন:

// Specify the list of fields to return.
final List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);

// Define the routing parameters object and pass the routing origin.
RoutingParameters routingParameters = RoutingParameters.builder()
    .setOrigin(toLatLng("-33.8688, 151.1957362"))
    .build();

// Use the builder to create a SearchByTextRequest object and pass the routing parameters.
// Set setRoutingSummariesIncluded to true.
final SearchByTextRequest searchByTextRequest = SearchByTextRequest.builder("Spicy Vegetarian Food in Sydney, Australia", placeFields)
    .setMaxResultCount(10)
    .setRoutingParameters(routingParameters)
    .setRoutingSummariesIncluded(true)
    .build();

// Call PlacesClient.searchByText() to perform the search.
// Define a response handler to process the returned Lists of Place objects, RoutingSummary objects, and Leg objects.
placesClient.searchByText(searchByTextRequest)   
    .addOnSuccessListener(response -> {
      List<Place> places = response.getPlaces();
      List<RoutingSummary> routingSummaries = response.getRoutingSummaries();
      List<Leg> legs = routingSummaries.get(0).getLegs();
      Duration duration = legs.get(0).getDuration();
    });

SearchByTextResponse ক্লাসটি একটি সার্চ রিকোয়েস্টের রেসপন্সকে উপস্থাপন করে। রাউটিং সামারিগুলোর তালিকা ফেরত পেতে আপনি SearchByTextResponse.getRoutingSummaries() কল করতে পারেন। একটি SearchByTextResponse অবজেক্টে আরও থাকে:

  • Place অবজেক্টের একটি তালিকা যা সমস্ত মিলে যাওয়া স্থানগুলিকে প্রতিনিধিত্ব করে, যেখানে প্রতিটি মিলে যাওয়া স্থানের জন্য একটি করে Place অবজেক্ট থাকে।
  • প্রতিটি Place অবজেক্টে শুধুমাত্র অনুরোধে পাঠানো ফিল্ড তালিকা দ্বারা সংজ্ঞায়িত ফিল্ডগুলোই থাকে।

এই উদাহরণে, আপনি 'নিকটবর্তী অনুসন্ধান' (Nearby Search) প্রতিক্রিয়ার প্রতিটি স্থানের ভ্রমণের সময়কাল এবং দূরত্ব গণনা করবেন। এই উদাহরণটি অস্ট্রেলিয়ার সিডনিতে রেস্তোরাঁ অনুসন্ধান করে এবং অবস্থানের সীমাবদ্ধতা ও রাউটিংয়ের উৎস একই অক্ষাংশ এবং দ্রাঘিমাংশ স্থানাঙ্কে নির্ধারণ করে:

// Specify the list of fields to return.
final List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);

// Define the search area as a 500 meter diameter circle in Sydney, Australia.
LatLng center = new LatLng(-33.8688, 151.1957362);
CircularBounds circle = CircularBounds.newInstance(center, /* radius = */ 500);

// Define the routing parameters object and pass the routing origin.
RoutingParameters routingParameters = RoutingParameters.builder()
    .setOrigin(toLatLng("-33.8688, 151.1957362"))
    .build();

// Use the builder to create a SearchNearbyRequest object and pass the routing parameters.
// Set setRoutingSummariesIncluded to true.
final SearchNearbyRequest searchNearbyRequest =
SearchNearbyRequest.builder(/* location restriction = */ circle, placeFields)
    .setIncludedTypes(includedTypes)
    .setMaxResultCount(10)
    .setRoutingParameters(routingParameters)
    .setRoutingSummariesIncluded(true)
    .build();

// Call PlacesClient.searchNearby() to perform the search.
// Define a response handler to process the returned Lists of Place objects, RoutingSummary objects, and Leg objects.
placesClient.searchNearby(searchNearbyRequest)
    .addOnSuccessListener(response -> {
      List<Place> places = response.getPlaces();
      List<RoutingSummary> routingSummaries = response.getRoutingSummaries();
      List<Leg> legs = routingSummaries.get(0).getLegs();
      Duration duration = legs.get(0).getDuration();
    });

SearchNearbyResponse ক্লাসটি একটি সার্চ রিকোয়েস্টের রেসপন্সকে উপস্থাপন করে। রাউটিং সামারিগুলোর তালিকা ফেরত পেতে আপনি SearchNearbyResponse.getRoutingSummaries() কল করতে পারেন। একটি SearchNearbyResponse অবজেক্টে আরও থাকে:

  • Place অবজেক্টের একটি তালিকা যা সমস্ত মিলে যাওয়া স্থানগুলিকে প্রতিনিধিত্ব করে, যেখানে প্রতিটি মিলে যাওয়া স্থানের জন্য একটি করে Place অবজেক্ট থাকে।
  • প্রতিটি Place অবজেক্টে শুধুমাত্র অনুরোধে পাঠানো ফিল্ড তালিকা দ্বারা সংজ্ঞায়িত ফিল্ডগুলোই থাকে।

অবস্থান সীমাবদ্ধতা এবং রাউটিং উৎসের জন্য আপনাকে একই স্থানাঙ্ক ব্যবহার করতে হবে না। উদাহরণস্বরূপ, আপনি অনুসন্ধানের ফলাফলকে ওই বৃত্তের মধ্যে সীমাবদ্ধ রাখতে অবস্থান সীমাবদ্ধতা সিডনির কেন্দ্রবিন্দুতে সেট করলেন। কিন্তু এরপর আপনি রাউটিং উৎসটি আপনার বাড়ির স্থানাঙ্কে সেট করলেন, অর্থাৎ অনুসন্ধানের বৃত্তের মধ্যে একটি ভিন্ন অবস্থানে। তখন অনুরোধটি অনুসন্ধানের ফলাফলকে ওই বৃত্তের মধ্যে সীমাবদ্ধ করে এবং আপনার বাড়ির অবস্থানের উপর ভিত্তি করে রাউটিং সারাংশ গণনা করে।

ভ্রমণের বিকল্পগুলি নির্দিষ্ট করুন

ডিফল্টরূপে, সময়কাল এবং দূরত্বের হিসাব একটি গাড়ির জন্য করা হয়। তবে, আপনি অনুসন্ধানের সময় গাড়ির ধরনসহ অন্যান্য বিকল্পগুলোও নিয়ন্ত্রণ করতে পারেন।

পরবর্তী উদাহরণে, আপনি ভ্রমণের মোড হিসেবে DRIVE নির্দিষ্ট করেছেন এবং হাইওয়ে এড়িয়ে চলতে বলেছেন:

// Specify the list of fields to return.
final List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);

// Define the routing modifiers object.
RouteModifiers routeModifiers = RouteModifiers.builder()
    .setAvoidHighways(true)
    .build();

// Define the routing parameters object and pass the routing origin.
RoutingParameters routingParameters = RoutingParameters.builder()
    .setOrigin(toLatLng("-33.8688, 151.1957362"))
    .setTravelMode(DRIVE)
    .setRouteModifiers(routeModifiers)
    .build();

// Use the builder to create a SearchByTextRequest object and pass the routing parameters.
// Set setRoutingSummariesIncluded to true.
final SearchByTextRequest searchByTextRequest = SearchByTextRequest.builder("Spicy Vegetarian Food in Sydney, Australia", placeFields)
    .setMaxResultCount(10)
    .setRoutingParameters(routingParameters)
    .setRoutingSummariesIncluded(true)
    .build();

// Call PlacesClient.searchByText() to perform the search.
// Define a response handler to process the returned Lists of Place objects, RoutingSummary objects, and Leg objects.
placesClient.searchByText(searchByTextRequest)   
    .addOnSuccessListener(response -> {
      List<Place> places = response.getPlaces();
      List<RoutingSummary> routingSummaries = result.getRoutingSummaries();
      List<Leg> legs = routingSummaries.get(0).getLegs();
      Duration duration = legs.get(0).getDuration();
    });