রাউটিংয়ের সারসংক্ষেপ গণনা করুন

উত্তরে প্রতিটি জায়গায় পৌঁছাতে কত সময় লাগবে এবং দূরত্ব কত তা গণনা করতে Text Search (New) বা Nearby Search (New) ব্যবহার করতে:

  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();
    });