Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Kết hợp thông tin tóm tắt về đường đi với tính năng tìm dọc theo tuyến đường
Bạn có thể kết hợp các phép tính tóm tắt về việc định tuyến với tính năng tìm kiếm dọc theo tuyến đường.
Trong trường hợp này, Tìm kiếm bằng văn bản (Mới) sẽ trả về thời gian di chuyển và khoảng cách đến từng địa điểm trong phản hồi, sau đó là từ từng địa điểm đến đích đến cuối cùng của tuyến đường.
Cách sử dụng tính năng Tìm kiếm bằng văn bản (Mới) để tính toán thông tin tóm tắt về việc định tuyến cùng với thông tin tìm kiếm dọc theo một tuyến đường:
Sử dụng tham số searchAlongRouteParameters.polyline.encodedPolyline để truyền đường đa tuyến đến tính năng Tìm kiếm bằng văn bản (Mới) nhằm điều chỉnh kết quả tìm kiếm theo tuyến đường. Sau đó, phản hồi sẽ chứa những địa điểm phù hợp với tiêu chí tìm kiếm và cũng nằm gần tuyến đường đã chỉ định.
Thêm routingSummaries vào mặt nạ trường để phản hồi bao gồm mảng routingSummaries. Mảng này chứa thời lượng và khoảng cách từ điểm bắt đầu định tuyến đến từng địa điểm trong phản hồi.
API Explorer cho phép bạn đưa ra các yêu cầu trực tiếp để có thể làm quen với API và các lựa chọn API:
Phản hồi chứa 2 mảng: mảng places chứa các địa điểm trùng khớp và mảng routingSummaries chứa thời lượng và khoảng cách di chuyển đến từng địa điểm:
{"places":[{"formattedAddress":"1199 El Camino Real, San Bruno, CA 94066, USA","priceLevel":"PRICE_LEVEL_INEXPENSIVE","displayName":{"text":"Vegan Mob - Vegan BBQ and Soul Food","languageCode":"en"}},{"formattedAddress":"839 Kearny St, San Francisco, CA 94108, USA","priceLevel":"PRICE_LEVEL_MODERATE","displayName":{"text":"Enjoy Vegetarian","languageCode":"en"}},…],"routingSummaries":[{"legs":[{"duration":"285s","distanceMeters":1616},{"duration":"2466s","distanceMeters":58147}],"directionsUri":"https://www.google.com/maps/dir/37.42268,-122.08473/''/37.77877,-122.38781/data=!4m7!4m6!1m0!1m2!1m1!1s0x808f87f9ede375f5:0xa37171fea1a16b28!1m0!3e0"},{"legs":[{"duration":"696s","distanceMeters":4704},{"duration":"2787s","distanceMeters":58901}],"directionsUri":"https://www.google.com/maps/dir/37.42268,-122.08473/''/37.77877,-122.38781/data=!4m7!4m6!1m0!1m2!1m1!1s0x808580f4cebdb06f:0xd3af09e5742234f2!1m0!3e0"},…]}
Đối với mỗi mục trong mảng legs, Tìm kiếm bằng văn bản (Mới) sẽ trả về thời gian của chuyến đi gồm 2 chặng:
Chặng đầu tiên chứa thời gian di chuyển và khoảng cách từ điểm khởi hành đến địa điểm. Trong ví dụ này, thời lượng và khoảng cách từ điểm xuất phát đến vị trí đầu tiên trong kết quả là 285 giây và 1.616 mét.
Chặng thứ hai chứa thời gian di chuyển và khoảng cách từ địa điểm đến điểm đến của tuyến đường. Trong ví dụ này, thời lượng và khoảng cách là 2466 giây và 58147 mét.
Chỉ định điểm bắt đầu định tuyến, chế độ di chuyển và các đối tượng sửa đổi tuyến đường
Bạn có thể sửa đổi cách tính tóm tắt về tìm kiếm và định tuyến bằng cách chỉ định điểm bắt đầu định tuyến, phương tiện di chuyển, các thông số sửa đổi tuyến đường và lựa chọn ưu tiên về định tuyến. Chế độ di chuyển và các đối tượng sửa đổi tuyến đường hoạt động giống như khi tính toán thông tin tóm tắt về việc định tuyến mà không cần chỉ định tuyến đường như minh hoạ trong chủ đề Chỉ định các lựa chọn di chuyển.
Theo mặc định, chặng đầu tiên của mỗi kết quả chứa khoảng cách từ điểm xuất phát do đường nhiều đoạn xác định đến từng địa điểm. Tuy nhiên, bạn có thể ghi đè giá trị mặc định đó bằng cách chỉ định rõ ràng một nguồn gốc định tuyến trong yêu cầu. Nếu được chỉ định, chặng đầu tiên của tất cả các phản hồi sẽ chỉ định khoảng cách và thời lượng từ điểm bắt đầu định tuyến đã chỉ định, ghi đè điểm bắt đầu từ đường nhiều đường.
Trong ví dụ tiếp theo, bạn chỉ định điểm bắt đầu của tuyến đường là toạ độ của San Mateo, California, chỉ định tránh đường thu phí và đặt số lượng kết quả thành 5:
Hình ảnh sau đây cho thấy một bản đồ có chứa đường nhiều đường, điểm xuất phát mới (ghim màu xanh dương nhạt) và các địa điểm trong kết quả tìm kiếm (ghim màu xanh lục). Lưu ý cách tất cả kết quả nằm dọc theo tuyến đường, nhưng sau San Mateo:
Hãy dùng thử!
Trình khám phá API cho phép bạn đưa ra các yêu cầu mẫu để có thể làm quen với API và các lựa chọn API.
Chọn biểu tượng API api ở bên phải trang.
Bạn có thể chỉnh sửa các tham số yêu cầu (không bắt buộc).
Chọn nút Thực thi. Trong hộp thoại, hãy chọn tài khoản mà bạn muốn dùng để đưa ra yêu cầu.
Trong bảng điều khiển APIs Explorer, hãy chọn biểu tượng toàn màn hình fullscreen để mở rộng cửa sổ APIs Explorer.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-04 UTC."],[[["\u003cp\u003eCombine routing summaries with search along a route to get travel duration and distance to places along a route, and from those places to the final destination.\u003c/p\u003e\n"],["\u003cp\u003eUse the Routes API to generate a route polyline, then provide it to Text Search (New) to bias results near the route and calculate routing summaries.\u003c/p\u003e\n"],["\u003cp\u003eInclude \u003ccode\u003eroutingSummaries\u003c/code\u003e in the field mask to receive duration and distance information, and optionally specify \u003ccode\u003eroutingParameters\u003c/code\u003e to customize origin, travel mode, and route modifiers.\u003c/p\u003e\n"],["\u003cp\u003eText Search (New) returns a two-leg trip time: the first leg is from the origin to the place, and the second leg is from the place to the route's final destination.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize the routing summary calculations by providing the routing origin, travel mode, route modifiers, and routing preferences in the request.\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/web-service/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 the `searchAlongRouteParameters.polyline.encodedPolyline` parameter 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. Include `routingSummaries` in the field mask so that the response includes\n the `routingSummaries` array. This array contains the duration and distance\n from the routing origin to each place in the response.\n\n | **Note:** Adding `routingSummaries` in the field mask without also including either the `routingParameters.origin` parameter or the `searchAlongRouteParameters.polyline.encodedPolyline` parameter in the request causes an error.\n\nThe APIs Explorer lets you make live requests so that you can get familiar with\nthe API and the API options: \n[Try it!](#try_it)\n\nBy default, Text Search (New) performs the search along the entire route: \n\n```scdoc\ncurl -X POST -d '{\n \"textQuery\" : \"Spicy Vegetarian Food\",\n \"searchAlongRouteParameters\": {\n \"polyline\": {\n \"encodedPolyline\": \"\u003cvar translate=\"no\"\u003eROUTE_POLYLINE\u003c/var\u003e\"\n }\n }\n}' \\\n-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: API_KEY' \\\n-H 'X-Goog-FieldMask: places.displayName,places.formattedAddress,places.priceLevel,routingSummaries' \\\n'https://places.googleapis.com/v1/places:searchText'\n```\n\nThe response contains two arrays: the `places` array containing the matching\nplaces, and the `routingSummaries` array containing the duration and distance to\ntravel to each place: \n\n```json\n{\n \"places\": [\n {\n \"formattedAddress\": \"1199 El Camino Real, San Bruno, CA 94066, USA\",\n \"priceLevel\": \"PRICE_LEVEL_INEXPENSIVE\",\n \"displayName\": {\n \"text\": \"Vegan Mob - Vegan BBQ and Soul Food\",\n \"languageCode\": \"en\"\n }\n },\n {\n \"formattedAddress\": \"839 Kearny St, San Francisco, CA 94108, USA\",\n \"priceLevel\": \"PRICE_LEVEL_MODERATE\",\n \"displayName\": {\n \"text\": \"Enjoy Vegetarian\",\n \"languageCode\": \"en\"\n }\n },\n ...\n],\n \"routingSummaries\": [\n {\n \"legs\": [\n {\n \"duration\": \"285s\",\n \"distanceMeters\": 1616\n },\n {\n \"duration\": \"2466s\",\n \"distanceMeters\": 58147\n }\n ],\n \"directionsUri\": \"https://www.google.com/maps/dir/37.42268,-122.08473/''/37.77877,-122.38781/data=!4m7!4m6!1m0!1m2!1m1!1s0x808f87f9ede375f5:0xa37171fea1a16b28!1m0!3e0\"\n },\n {\n \"legs\": [\n {\n \"duration\": \"696s\",\n \"distanceMeters\": 4704\n },\n {\n \"duration\": \"2787s\",\n \"distanceMeters\": 58901\n }\n ],\n \"directionsUri\": \"https://www.google.com/maps/dir/37.42268,-122.08473/''/37.77877,-122.38781/data=!4m7!4m6!1m0!1m2!1m1!1s0x808580f4cebdb06f:0xd3af09e5742234f2!1m0!3e0\"\n },\n ...\n ]\n}\n```\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. In this example, the duration and distance from the origin to the\n first place in the results is 285 seconds and 1616 meters.\n\n- The second leg contains the travel duration and distance from the place to\n the route destination. In this example, the duration and distance is\n 2466 seconds and 58147 meters.\n\n| **Note:** This response also includes the Preview (pre-GA) `directionsUri` field in the routing summary for each place. This field contains a link to open directions to the place in Google Maps. The polyline origin or the `routingParameters.origin` parameter specifies directions origin, the polyline destination specifies the directions destination, and the travel mode is drive. The directions start at the origin, proceed to the place as a waypoint, and end at the route destination.\n| This product or feature is in Preview (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google\n| Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage\n| descriptions](/maps/launch-stages).\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/web-service/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```scdoc\n curl -X POST -d '{\n \"textQuery\" : \"Spicy Vegetarian Food\",\n \"maxResultCount\": 5,\n \"searchAlongRouteParameters\": {\n \"polyline\": {\n \"encodedPolyline\": \"\u003cvar translate=\"no\"\u003eROUTE_POLYLINE\u003c/var\u003e\"\n }\n },\n \"routingParameters\": {\n \"origin\": {\n \"latitude\": 37.56617,\n \"longitude\": -122.30870\n },\n \"travelMode\":\"DRIVE\",\n \"routeModifiers\": {\n \"avoidTolls\": true\n }\n }\n }' \\\n -H 'Content-Type: application/json' -H 'X-Goog-Api-Key: API_KEY' \\\n -H 'X-Goog-FieldMask: places.displayName,places.formattedAddress,places.priceLevel,routingSummaries' \\\n 'https://places.googleapis.com/v1/places:searchText'\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:\n\nTry it!\n-------\n\nThe APIs Explorer lets you make sample requests so\nthat you can get familiar with the API and the API options.\n\n1. Select the API icon api\n on the right side of the page.\n\n2. Optionally edit the request parameters.\n\n3. Select the **Execute** button. In the dialog, choose the account\n that you want to use to make the request.\n\n4. In the APIs Explorer panel, select the fullscreen icon\n fullscreen to expand the APIs Explorer window."]]