রাউটিংয়ের সারসংক্ষেপ গণনা করুন
উত্তরে প্রতিটি জায়গায় পৌঁছাতে কত সময় লাগবে এবং দূরত্ব কত তা গণনা করতে Text Search (New) বা Nearby Search (New) ব্যবহার করতে:
-
অনুরোধে
RoutingParametersপ্যারামিটার পাস করুন,setOrigin()ব্যবহার করে রাউটিংয়ের উৎসের অক্ষাংশ ও দ্রাঘিমাংশ স্থানাঙ্ক নির্দিষ্ট করুন। উত্তরে প্রতিটি জায়গার সময়সীমা ও দূরত্ব গণনা করার জন্য এই প্যারামিটার প্রয়োজন। -
অনুরোধ অবজেক্ট তৈরি করার সময়
.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অবজেক্টে শুধুমাত্র অনুরোধে পাস করা ফিল্ড লিস্টের মাধ্যমে সংজ্ঞায়িত ফিল্ড থাকে।
নিয়ারবাই Search ব্যবহার করা
এই উদাহরণে, আপনি 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,BICYCLE,WALKবাTWO_WHEELER-এ পরিবহনের মোড সেট করতেroutingParameters.setTravelMode()ব্যবহার করুন। এইসব বিকল্প সম্পর্কে আরও তথ্য পেতে, রুটের জন্য উপলভ্য গাড়ির ধরন দেখুন। -
রাউটিং সংক্রান্ত পছন্দ বিকল্পকে
TRAFFIC_UNAWARE(ডিফল্ট),TRAFFIC_AWAREবাTRAFFIC_AWARE_OPTIMALহিসেবে সেট করতেroutingParameters.setRoutingPreference()ব্যবহার করুন। প্রতিটি বিকল্পে ডেটার কোয়ালিটি ও লেটেন্সি আলাদা আলাদা হয়। আরও তথ্যের জন্য, ট্রাফিক ডেটা কীভাবে এবং অন্তর্ভুক্ত করা হবে কিনা তা নির্দিষ্ট করুন দেখুন। -
routingParameters.setRouteModifiers()ব্যবহার করেavoidTolls,avoidHighways,avoidFerriesওavoidIndoor-এর জন্য নির্দিষ্ট করুন। এইসব বিকল্প সম্পর্কে আরও জানতে, এড়িয়ে যাওয়ার জন্য রুটের ফিচার নির্দিষ্ট করুন দেখুন।
পরবর্তী উদাহরণে, আপনি ভ্রমণের মোড 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(); });