קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
שילוב של סיכומי ניתוב עם חיפוש לאורך המסלול
אפשר לשלב בין חישובים של סיכום מסלול לבין חיפוש לאורך מסלול.
במקרה כזה, חיפוש טקסט (חדש) מחזיר בתשובה את משך הנסיעה והמרחק לכל מקום, ואז מכל מקום ליעד הסופי של המסלול.
כדי להשתמש בחיפוש טקסט (חדש) כדי לחשב את סיכום הניתוב יחד עם חיפוש לאורך מסלול:
משתמשים ב-searchAlongRouteParameters.setPolyline() כדי להעביר את קו המסלול לחיפוש טקסט (חדש) כדי להטות את תוצאות החיפוש למסלול. התשובה תכיל מקומות שתואמים לקריטריונים לחיפוש
וגם ממוקמים בקרבת המסלול שצוין.
כשיוצרים את אובייקט הבקשה, מוסיפים את .setRoutingSummariesIncluded(true).
כברירת מחדל, חיפוש טקסט (חדש) מבצע את החיפוש לאורך כל המסלול:
// Define the route polyline object using the route string.EncodedPolylineencodedPolyline=EncodedPolyline.newInstance("wblcFptchVIFOd@G@EVw@Ms@dHKR}ApNA`AF~@Hf@TjAb@bBb@~@n@p@^Rd@~@Vz@HVz@nDLt@?d@Kr@c@~@mD`G?`@aEfGkCnDuChDm`@bb@[`@{GhHeEdEciBnnBkC`DkC~DaClEuKjT_Z|l@Qb@iR~_@}EzJ_AdB_Und@kAfCaOjZkg@vcAqBzD_]rr@iBlEaBxEgArD}AlG}AhHsA`IeAnH{@dIq@dJgL~iBq@rHu@vGgAtHwArHaBhHkBzG_DpJ}Nbc@iBhGkA|EgC|LcIjb@oAhG_AvDgAdDkApC_BzCiBpCsFvGii@vn@scAxlAmLjNgSzUeRjT{TzWqExEmG|FuNlMmMhLaRvPqOlNmbAl}@mFlF{PlOmJfIoElE}LtMiSbU_H`I}}@jcAwl@vp@oAbBqA~BeAhCm@tBg@fCWrBQ~BI|DaB~rBO~D[bEa@`Dm@pDaAdE{@vC_BbEkB~Def@|z@sEzHKJeS~]}K`S{\\~l@cXpe@sBpDm@bAuCxDkBrBiC~BwCtByBnAcBx@}Bt@{Bn@gh@|LaOpDeFhAoDj@aE^kVrA_E^iEr@yD~@uBr@gMjF_EnAcCh@eFr@_DRsAD}@Jsu@xCWDqIV}BCeCOyDm@cBa@_DmA}JeE_CwAsBcBiBoBuAqBmOoX{CuEkB_CoDqDkVoUoD{CeE_DkEkC_FeCqB}@sDuAoDgAeCe@cCW}CK}BDaDTeOlBcuBrYaNlBq@Dyd@rGyFt@yBb@eBf@oCnAoBlAkIpGkAp@wBbAaCt@oFdAwKjBoGxA{FbByIjC_HfB_@KmNdDuC|@uFzBcH|C{@\\[?sBv@}@VaBVoA@y@EmAQcA[w@]aBkAeAkA}BuDUKs@uAqBsCwBcCgAiAiN_MyKsJsG{GkBaBiBuA{BwAwDkBcOaHiC_AiCg@}BQcCAcBHqBVkB`@qEjAu@LgCVgAHwG@sG?mABsH^eNr@mBXy@NqBt@uAt@aBlAkAlA}BtCyApBiAdB_BxB{A`B}@j@oAf@s@PeCVcIf@gAAkAQy@YiAo@_A{@_DgEgJqM_DeEaM}PoBiCzAsBw@kAdAGVk@f@q@z@C");// Specify the list of fields to return.finalList<Place.Field>placeFields=Arrays.asList(Place.Field.ID,Place.Field.NAME);// Define the search along route parameters object and pass the polyline object.SearchAlongRouteParameterssearchAlongRouteParameters=SearchAlongRouteParameters.builder().setPolyline(encodedPolyline).build();// Use the builder to create a SearchByTextRequest object and pass the search along route parameters.finalSearchByTextRequestsearchByTextRequest=SearchByTextRequest.builder("Spicy Vegetarian Food",placeFields).setMaxResultCount(10).setSearchAlongRouteParameters(searchAlongRouteParameters).setRoutingSummariesIncluded(true).build();// Call PlacesClient.searchByText() to perform the search.// Define a response handler to process the returned List of Place objects.placesClient.searchByText(searchByTextRequest).addOnSuccessListener(response->{List<Place>places=response.getPlaces();List<RoutingSummary>routingSummaries=response.getRoutingSummaries();List<Leg>legs=routingSummaries.get(0).getLegs();Durationduration=legs.get(0).getDuration();});
התשובה מכילה אובייקטים שכוללים רשימות של שדות המקומות המבוקשים וסיכומי ניתוב שמכילים את משך הנסיעה והמרחק לכל מקום.
אפשר להתקשר אל SearchByTextResponse.getRoutingSummaries() כדי להחזיר את רשימת סיכומי הניתוב.
לכל רשומה במערך legs, פונקציית חיפוש הטקסט (חדשה) מחזירה את משך הנסיעה בשני קטעי הדרך:
הקטע הראשון מכיל את משך הנסיעה והמרחק מנקודת המוצא למקום.
הקטע השני מכיל את משך הנסיעה והמרחק מהמקום ליעד של המסלול.
ציון מוצא הניתוב, אמצעי התחבורה ושינויים במסלול
אתם יכולים לשנות את החישוב של סיכום החיפוש והניתוב על ידי ציון של מוצא הניתוב, מצב הנסיעה, שינויים במסלול והעדפות הניתוב. אמצעי התחבורה והשינויים במסלול פועלים באותו אופן כמו בחישוב סיכומי מסלולים בלי לציין מסלול, כפי שמוסבר בנושא ציון אפשרויות נסיעה.
כברירת מחדל, המרחק מנקודת המוצא שמוגדרת על ידי הקו המקוטע לכל מקום מופיע בקטע הראשון של כל תוצאה. אבל אפשר לבטל את ברירת המחדל הזו על ידי ציון מקור ניתוב מפורש בבקשה. אם מציינים את נקודת המוצא, הרגל הראשון של כל התגובות מציין את המרחקים והמשך מהמקור שצוין לניתוב, ומבטל את המקור מהקו המקוקו.
בדוגמה הבאה, מציינים את נקודת המוצא של הניתוב כקואורדינטות של סן מטאו בקליפורניה, מציינים להימנע מתשלום אגרה ומגדירים את מספר התוצאות ל-5:
// Define the route polyline object using the route string.EncodedPolylineencodedPolyline=EncodedPolyline.newInstance("wblcFptchVIFOd@G@EVw@Ms@dHKR}ApNA`AF~@Hf@TjAb@bBb@~@n@p@^Rd@~@Vz@HVz@nDLt@?d@Kr@c@~@mD`G?`@aEfGkCnDuChDm`@bb@[`@{GhHeEdEciBnnBkC`DkC~DaClEuKjT_Z|l@Qb@iR~_@}EzJ_AdB_Und@kAfCaOjZkg@vcAqBzD_]rr@iBlEaBxEgArD}AlG}AhHsA`IeAnH{@dIq@dJgL~iBq@rHu@vGgAtHwArHaBhHkBzG_DpJ}Nbc@iBhGkA|EgC|LcIjb@oAhG_AvDgAdDkApC_BzCiBpCsFvGii@vn@scAxlAmLjNgSzUeRjT{TzWqExEmG|FuNlMmMhLaRvPqOlNmbAl}@mFlF{PlOmJfIoElE}LtMiSbU_H`I}}@jcAwl@vp@oAbBqA~BeAhCm@tBg@fCWrBQ~BI|DaB~rBO~D[bEa@`Dm@pDaAdE{@vC_BbEkB~Def@|z@sEzHKJeS~]}K`S{\\~l@cXpe@sBpDm@bAuCxDkBrBiC~BwCtByBnAcBx@}Bt@{Bn@gh@|LaOpDeFhAoDj@aE^kVrA_E^iEr@yD~@uBr@gMjF_EnAcCh@eFr@_DRsAD}@Jsu@xCWDqIV}BCeCOyDm@cBa@_DmA}JeE_CwAsBcBiBoBuAqBmOoX{CuEkB_CoDqDkVoUoD{CeE_DkEkC_FeCqB}@sDuAoDgAeCe@cCW}CK}BDaDTeOlBcuBrYaNlBq@Dyd@rGyFt@yBb@eBf@oCnAoBlAkIpGkAp@wBbAaCt@oFdAwKjBoGxA{FbByIjC_HfB_@KmNdDuC|@uFzBcH|C{@\\[?sBv@}@VaBVoA@y@EmAQcA[w@]aBkAeAkA}BuDUKs@uAqBsCwBcCgAiAiN_MyKsJsG{GkBaBiBuA{BwAwDkBcOaHiC_AiCg@}BQcCAcBHqBVkB`@qEjAu@LgCVgAHwG@sG?mABsH^eNr@mBXy@NqBt@uAt@aBlAkAlA}BtCyApBiAdB_BxB{A`B}@j@oAf@s@PeCVcIf@gAAkAQy@YiAo@_A{@_DgEgJqM_DeEaM}PoBiCzAsBw@kAdAGVk@f@q@z@C");// Specify the list of fields to return.finalList<Place.Field>placeFields=Arrays.asList(Place.Field.ID,Place.Field.NAME);// Define the routing modifiers object.RouteModifiersrouteModifiers=RouteModifiers.builder().setAvoidTolls(true).build();// Define the routing parameters object and pass the routing origin.// Set the travel mode to DRIVE.// Pass the routeModifiers object.RoutingParametersroutingParameters=RoutingParameters.builder().setOrigin(toLatLng("37.56617, -122.30870")).setTravelMode(DRIVE).setRouteModifiers(routeModifiers).build();// Define the search along route parameters object and pass the polyline object.SearchAlongRouteParameterssearchAlongRouteParameters=SearchAlongRouteParameters.builder().setPolyline(encodedPolyline).build();// Use the builder to create a SearchByTextRequest object and pass the search along route parameters.finalSearchByTextRequestsearchByTextRequest=SearchByTextRequest.builder("Spicy Vegetarian Food",placeFields).setMaxResultCount(5).setRoutingParameters(routingParameters).setSearchAlongRouteParameters(searchAlongRouteParameters).setRoutingSummariesIncluded(true).build();// Call PlacesClient.searchByText() to perform the search.// Define a response handler to process the returned List of Place objects.placesClient.searchByText(searchByTextRequest).addOnSuccessListener(response->{List<Place>places=response.getPlaces();List<RoutingSummary>routingSummaries=result.getRoutingSummaries();List<Leg>legs=routingSummaries.get(0).getLegs();Durationduration=legs.get(0).getDuration();});
בתמונה הבאה מוצגת מפה שמכילה את קו הפוליגון של המסלול, את נקודת המוצא החדשה (סיכה בצבע תכלת) ואת המקומות בתוצאות החיפוש (סיכות בצבע ירוק). שימו לב שכל התוצאות נמצאות לאורך המסלול, אבל אחרי סן מתאו:
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-09-04 (שעון UTC)."],[[["\u003cp\u003eCombine routing summary calculations with search along a route to find places near a specific route with travel duration and distance included.\u003c/p\u003e\n"],["\u003cp\u003eText Search (New) with \u003ccode\u003esearchAlongRouteParameters\u003c/code\u003e and \u003ccode\u003esetRoutingSummariesIncluded(true)\u003c/code\u003e enables searching for places along a defined route polyline.\u003c/p\u003e\n"],["\u003cp\u003eResponses include routing summaries with two-leg trip times: origin to place and place to route destination.\u003c/p\u003e\n"],["\u003cp\u003eCustomize the search by specifying routing origin, travel mode, and route modifiers like avoiding tolls, influencing travel time and distance calculations.\u003c/p\u003e\n"],["\u003cp\u003eThe response provides travel duration and distance for each leg, but not the route itself; use the Routes API with origin, place, and destination for route calculation.\u003c/p\u003e\n"]]],[],null,["Combine routing summaries with search along route\n=================================================\n\nYou can combine **routing summary** calculations with **search along a route** .\nIn this case, [Text Search (New)](/maps/documentation/places/android-sdk/text-search) returns the travel duration and distance to each\nplace in the response, and then from each place to the final destination of the\nroute.\n\nTo use Text Search (New) to calculate the routing summary along with search\nalong a route:\n\n1. Use the Routes API to calculate a route that [returns a route polyline](/maps/documentation/routes/traffic_on_polylines)\n in the response.\n\n2. Use `searchAlongRouteParameters.setPolyline()` to\n pass the route polyline to Text Search (New) to bias the search results to\n the route. The response then contains places that match the search criteria\n and are also located near the specified route.\n\n3. When building the request object, add `.setRoutingSummariesIncluded(true)`.\n\nBy default, Text Search (New) performs the search along the entire route: \n\n```java\n// Define the route polyline object using the route string.\nEncodedPolyline encodedPolyline = EncodedPolyline.newInstance(\"wblcFptchVIFOd@G@EVw@Ms@dHKR}ApNA`AF~@Hf@TjAb@bBb@~@n@p@^Rd@~@Vz@HVz@nDLt@?d@Kr@c@~@mD`G?`@aEfGkCnDuChDm`@bb@[`@{GhHeEdEciBnnBkC`DkC~DaClEuKjT_Z|l@Qb@iR~_@}EzJ_AdB_Und@kAfCaOjZkg@vcAqBzD_]rr@iBlEaBxEgArD}AlG}AhHsA`IeAnH{@dIq@dJgL~iBq@rHu@vGgAtHwArHaBhHkBzG_DpJ}Nbc@iBhGkA|EgC|LcIjb@oAhG_AvDgAdDkApC_BzCiBpCsFvGii@vn@scAxlAmLjNgSzUeRjT{TzWqExEmG|FuNlMmMhLaRvPqOlNmbAl}@mFlF{PlOmJfIoElE}LtMiSbU_H`I}}@jcAwl@vp@oAbBqA~BeAhCm@tBg@fCWrBQ~BI|DaB~rBO~D[bEa@`Dm@pDaAdE{@vC_BbEkB~Def@|z@sEzHKJeS~]}K`S{\\\\~l@cXpe@sBpDm@bAuCxDkBrBiC~BwCtByBnAcBx@}Bt@{Bn@gh@|LaOpDeFhAoDj@aE^kVrA_E^iEr@yD~@uBr@gMjF_EnAcCh@eFr@_DRsAD}@Jsu@xCWDqIV}BCeCOyDm@cBa@_DmA}JeE_CwAsBcBiBoBuAqBmOoX{CuEkB_CoDqDkVoUoD{CeE_DkEkC_FeCqB}@sDuAoDgAeCe@cCW}CK}BDaDTeOlBcuBrYaNlBq@Dyd@rGyFt@yBb@eBf@oCnAoBlAkIpGkAp@wBbAaCt@oFdAwKjBoGxA{FbByIjC_HfB_@KmNdDuC|@uFzBcH|C{@\\\\[?sBv@}@VaBVoA@y@EmAQcA[w@]aBkAeAkA}BuDUKs@uAqBsCwBcCgAiAiN_MyKsJsG{GkBaBiBuA{BwAwDkBcOaHiC_AiCg@}BQcCAcBHqBVkB`@qEjAu@LgCVgAHwG@sG?mABsH^eNr@mBXy@NqBt@uAt@aBlAkAlA}BtCyApBiAdB_BxB{A`B}@j@oAf@s@PeCVcIf@gAAkAQy@YiAo@_A{@_DgEgJqM_DeEaM}PoBiCzAsBw@kAdAGVk@f@q@z@C\n\");\n\n// Specify the list of fields to return.\nfinal List\u003cPlace.Field\u003e placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);\n\n// Define the search along route parameters object and pass the polyline object.\nSearchAlongRouteParameters searchAlongRouteParameters = SearchAlongRouteParameters.builder()\n .setPolyline(encodedPolyline)\n .build();\n\n// Use the builder to create a SearchByTextRequest object and pass the search along route parameters.\nfinal SearchByTextRequest searchByTextRequest = SearchByTextRequest.builder(\"Spicy Vegetarian Food\", placeFields)\n .setMaxResultCount(10)\n .setSearchAlongRouteParameters(searchAlongRouteParameters)\n .setRoutingSummariesIncluded(true)\n .build();\n\n// Call PlacesClient.searchByText() to perform the search.\n// Define a response handler to process the returned List of Place objects.\nplacesClient.searchByText(searchByTextRequest) \n .addOnSuccessListener(response -\u003e {\n List\u003cPlace\u003e places = response.getPlaces();\n List\u003cRoutingSummary\u003e routingSummaries = response.getRoutingSummaries();\n List\u003cLeg\u003e legs = routingSummaries.get(0).getLegs();\n Duration duration = legs.get(0).getDuration();\n });\n```\n\n\nThe response contains objects that include lists of the requested places fields and routing\nsummaries containing the duration and distance to travel to each place.\nYou can call [`SearchByTextResponse.getRoutingSummaries()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/SearchByTextResponse#getRoutingSummaries()) to return the list of routing summaries.\n\nFor each entry in the `legs` array, Text Search (New) returns a **two-leg** trip\ntime:\n\n- The first leg contains the travel duration and distance from the origin to\n the place.\n\n- The second leg contains the travel duration and distance from the place to\n the route destination.\n\n| **Note:** The response only contains the travel duration and duration for each leg. It does not contain the actual route itself. To calculate the route, pass the origin, location of the place as an intermediate waypoint, and the destination into the Routes API.\n\nSpecify the routing origin, travel mode, and route modifiers\n------------------------------------------------------------\n\nYou can modify the search and routing summary calculation by specifying the\nrouting origin, travel mode, route modifiers, and routing preferences. The\ntravel mode and route modifiers work the same as for calculating routing\nsummaries without specifying a route as shown in the [Specify travel\noptions](/maps/documentation/places/android-sdk/routing-summary#travel-options) topic.\n\nBy default, the first leg of each result contains the distance from the origin\ndefined by the polyline to each place. However, you can override that default by\nexplicitly specifying a routing origin in the request. If specified, the first\nleg of all responses specifies the distances and duration from the specified\nrouting origin, overriding the origin from the polyline.\n\nIn the next example, you specify a routing origin as the coordinates of San\nMateo, CA, specify to avoid tolls, and set the number of results to 5: \n\n```java\n// Define the route polyline object using the route string.\nEncodedPolyline encodedPolyline = EncodedPolyline.newInstance(\"wblcFptchVIFOd@G@EVw@Ms@dHKR}ApNA`AF~@Hf@TjAb@bBb@~@n@p@^Rd@~@Vz@HVz@nDLt@?d@Kr@c@~@mD`G?`@aEfGkCnDuChDm`@bb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.asList(Place.Field.ID, Place.Field.NAME);\n\n// Define the routing modifiers object.\nRouteModifiers routeModifiers = RouteModifiers.builder()\n .setAvoidTolls(true)\n .build();\n\n// Define the routing parameters object and pass the routing origin.\n// Set the travel mode to DRIVE.\n// Pass the routeModifiers object.\nRoutingParameters routingParameters = RoutingParameters.builder()\n .setOrigin(toLatLng(\"37.56617, -122.30870\"))\n .setTravelMode(DRIVE)\n .setRouteModifiers(routeModifiers)\n .build();\n\n// Define the search along route parameters object and pass the polyline object.\nSearchAlongRouteParameters searchAlongRouteParameters = SearchAlongRouteParameters.builder()\n .setPolyline(encodedPolyline)\n .build();\n\n// Use the builder to create a SearchByTextRequest object and pass the search along route parameters.\nfinal SearchByTextRequest searchByTextRequest = SearchByTextRequest.builder(\"Spicy Vegetarian Food\", placeFields)\n .setMaxResultCount(5)\n .setRoutingParameters(routingParameters)\n .setSearchAlongRouteParameters(searchAlongRouteParameters)\n .setRoutingSummariesIncluded(true)\n .build();\n\n// Call PlacesClient.searchByText() to perform the search.\n// Define a response handler to process the returned List of Place objects.\nplacesClient.searchByText(searchByTextRequest) \n .addOnSuccessListener(response -\u003e {\n List\u003cPlace\u003e places = response.getPlaces();\n List\u003cRoutingSummary\u003e routingSummaries = result.getRoutingSummaries();\n List\u003cLeg\u003e legs = routingSummaries.get(0).getLegs();\n Duration duration = legs.get(0).getDuration();\n });\n```\n\nThe following image shows a map that contains the route polyline, the new origin\n(light-blue pin), and the places in the search results (green pins). Notice how\nall the results are along the route but past San Mateo:"]]