Google Directions API
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用 Google Directions API 解决 TSP
Google 还提供了一种方法来解决实际营业地点的简单 TSP,
下载 OR-工具。如果您有 Google Directions API 密钥,您可以解题,
真实营业地点的 TSP
Directions API
,在网址中提供位置并获取以 JSON 格式返回的响应。
您需要自己的数据
免费的 Directions API 密钥
企业密钥用于商业用途。
例如,您可以使用下面的网址查找简短的酿酒导览
最开始是阿德莱德如果您想从
请将网址末尾的 API_KEY 替换为您的密钥。
https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&key=API_KEY
结果将是一个详细说明解决方案的长 JSON 响应,其中包括
Google 地图路线:
{
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : -33.8347115,
"lng" : 140.8547058
},
"southwest" : {
"lat" : -37.3511758,
"lng" : 138.4951576
}
},
"copyrights" : "Map data ©2014 Google",
"legs" : [
{
"distance" : {
"text" : "139 km",
"value" : 139119
},
"duration" : {
"text" : "1 hour 51 mins",
"value" : 6648
},
"end_address" : "Clare SA 5453, Australia",
"end_location" : {
"lat" : -33.8333395,
"lng" : 138.6117283
},
"start_address" : "Adelaide SA, Australia",
"start_location" : {
"lat" : -34.9285894,
"lng" : 138.5999429
},
"steps" : [
{
"distance" : {
"text" : "70 m",
"value" : 70
},
"duration" : {
"text" : "1 min",
"value" : 6
},
"end_location" : {
"lat" : -34.9285338,
"lng" : 138.6007031
},
"html_instructions" : "Head \u003cb\u003eeast\u003c/b\u003e on \u003cb\u003eReconciliation Plaza\u003c/b\u003e toward \u003cb\u003eVictoria Square\u003c/b\u003e",
...
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-29。
[null,null,["最后更新时间 (UTC):2024-08-29。"],[[["\u003cp\u003eGoogle Directions API can be used to solve Traveling Salesperson Problems (TSPs) for real-world locations without needing OR-Tools.\u003c/p\u003e\n"],["\u003cp\u003eThis requires a Google Directions API key, obtainable for free for development or as an enterprise key for commercial purposes.\u003c/p\u003e\n"],["\u003cp\u003eBy providing locations within a structured URL, the API returns a JSON response detailing the optimal route and directions.\u003c/p\u003e\n"],["\u003cp\u003eThe response includes comprehensive information like distances, durations, and step-by-step navigation instructions.\u003c/p\u003e\n"]]],["The Google Directions API can solve Traveling Salesperson Problems (TSPs) for real-world locations. Users must obtain a Directions API key. By constructing a URL with locations as waypoints, the API returns a JSON response containing the optimized route. For example, a URL can be created to find a route between winemaking regions in South Australia starting in Adelaide. The returned JSON provides detailed directions for the solution, including distance, duration, and specific steps.\n"],null,["# Google Directions API\n\nSolving TSPs with the Google Directions API\n-------------------------------------------\n\nGoogle also provides a way to solve simple TSPs of real-world locations without\ndownloading OR-Tools. If you have a Google Directions API key, you can solve\nTSPs of real-world locations with the\n[Directions API](https://developers.google.com/maps/documentation/directions/#Waypoints)\n, providing the locations in a URL and getting the response back as JSON.\nYou'll need your own\n[free Directions API key](https://developers.google.com/maps/pricing-and-plans/)\nfor development, or an enterprise key for commercial use.\n\nAs an example, here's a URL that can be used to find a short tour of winemaking\nregions in South Australia, beginning in Adelaide. If you want to try this from\nyour browser, replace *API_KEY* at the end of the URL with your key. \n\n```\nhttps://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&key=API_KEY\n```\n\nThe result will be a long JSON response detailing the solution, complete with\nGoogle Maps directions: \n\n```carbon\n{\n \"routes\" : [\n {\n \"bounds\" : {\n \"northeast\" : {\n \"lat\" : -33.8347115,\n \"lng\" : 140.8547058\n },\n \"southwest\" : {\n \"lat\" : -37.3511758,\n \"lng\" : 138.4951576\n }\n },\n \"copyrights\" : \"Map data ©2014 Google\",\n \"legs\" : [\n {\n \"distance\" : {\n \"text\" : \"139 km\",\n \"value\" : 139119\n },\n \"duration\" : {\n \"text\" : \"1 hour 51 mins\",\n \"value\" : 6648\n },\n \"end_address\" : \"Clare SA 5453, Australia\",\n \"end_location\" : {\n \"lat\" : -33.8333395,\n \"lng\" : 138.6117283\n },\n \"start_address\" : \"Adelaide SA, Australia\",\n \"start_location\" : {\n \"lat\" : -34.9285894,\n \"lng\" : 138.5999429\n },\n \"steps\" : [\n {\n \"distance\" : {\n \"text\" : \"70 m\",\n \"value\" : 70\n },\n \"duration\" : {\n \"text\" : \"1 min\",\n \"value\" : 6\n },\n \"end_location\" : {\n \"lat\" : -34.9285338,\n \"lng\" : 138.6007031\n },\n \"html_instructions\" : \"Head \\u003cb\\u003eeast\\u003c/b\\u003e on \\u003cb\\u003eReconciliation Plaza\\u003c/b\\u003e toward \\u003cb\\u003eVictoria Square\\u003c/b\\u003e\",\n...\n```"]]