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

উত্তরে প্রতিটি স্থানের ভ্রমণের সময়কাল এবং দূরত্ব গণনা করতে টেক্সট অনুসন্ধান (নতুন) বা কাছাকাছি অনুসন্ধান (নতুন) ব্যবহার করতে:

  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 অবজেক্টে কেবল অনুরোধে পাস করা ফিল্ড তালিকা দ্বারা সংজ্ঞায়িত ক্ষেত্রগুলি থাকে।

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

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