{"id":2808,"date":"2023-12-22T19:48:27","date_gmt":"2023-12-22T19:48:27","guid":{"rendered":"https:\/\/developers.maplink.global\/example-2-displaying-a-route-generated-by-the-trip-api\/"},"modified":"2024-03-04T14:32:18","modified_gmt":"2024-03-04T14:32:18","slug":"example-2-displaying-a-route-generated-by-the-trip-api","status":"publish","type":"post","link":"https:\/\/developers.maplink.global\/en\/example-2-displaying-a-route-generated-by-the-trip-api\/","title":{"rendered":"Example 2 &#8211; Displaying a route generated by the Trip API"},"content":{"rendered":"\n<p>This example shows the result of a route between 2 points near Avenida Paulista in the city of S\u00e3o Paulo.<\/p>\n\n<p class=\"has-text-align-center\"><img loading=\"lazy\" decoding=\"async\" width=\"703\" height=\"412\" src=\"https:\/\/lh7-us.googleusercontent.com\/cULMIgHCJUF1WWJSZcB649ewvydyxZn0HzWO98lAr_9SqsuNjuwuxPXnkKToYHhv1_cIUbtntA5e-dfxip2OoKizTxFNKv1TMO5gZfyWKWky2ECMOFpr1tbO5XYVyEptCp8tnWb-OKSZyXZ8g5uvc5Y\"\/><\/p>\n\n<p>In the variable <code>apiKey<\/code>, add your key received from Maplink.<\/p>\n\n<p>The variable <code>map<\/code> is associated with the class <code>MaplinkMap<\/code> and contains the properties of the map, such as <code>div<\/code> where it will be initialized. In this case, there is no initial location defined, so the map will be centered automatically when the polyline is obtained in the method <code>line<\/code>.<\/p>\n\n<p>The method <code>map.line<\/code> obtains the latitude\/longitude coordinates of the response containing the route taken by the Trip API and adds it to the map in green.<\/p>\n\n<p>The <code>map.marker<\/code> method adds a marker at the beginning and end. As no <code>icon<\/code> has been declared, the default Maplink marker is displayed.<\/p>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;html&gt;\n  &lt;head&gt;\n    &lt;meta name=\"viewport\" content=\"initial-scale=1,maximum-scale=1,user-scalable=no\" \/&gt;\n    &lt;script src=\"https:\/\/maps.maplink.global\"&gt;&lt;\/script&gt;\n    &lt;style&gt;\n      #map {position: absolute; top: 0; right: 0; bottom: 0; left: 0;}\n    &lt;\/style&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;div id=\"map\"&gt;&lt;\/div&gt;\n    &lt;script type = \"text\/javascript\"&gt;\n          const apiKey = \"SUA CHAVE DE API\";\n          const map = new MaplinkMap(apiKey, \"map\");\n          \n          const tripSolution = JSON.parse(`{\n          \"id\": \"6099bda9059e8b46df94f8bc\",\n          \"clientId\": \"SUA CHAVE DE API\",\n          \"totalDistance\": 737,\n          \"totalNominalDuration\": 88,\n          \"averageSpeed\": 30.15,\n          \"legs\": [\n               {\n                    \"distance\": 737,\n                    \"nominalDuration\": 88,\n                    \"averageSpeed\": 30.15,\n                    \"points\": [\n                         {\n                              \"latitude\": -23.56650175288036,\n                              \"longitude\": -46.653812897469145\n                         },\n                         {\n                              \"latitude\": -23.564855,\n                              \"longitude\": -46.652203\n                         },\n                         {\n                              \"latitude\": -23.561890765824277,\n                              \"longitude\": -46.65578327260709\n                         }\n                    ]\n               }\n          ],\n          \"source\": \"MAPLINK\",\n          \"createdAt\": 1620688298404\n          }`);\n \n          const routePoints = tripSolution.legs[0].points;\n \n          map.line(routePoints, {\n               color: \"green\"\n          });\n \n          map.marker(routePoints[0], {\n               popup: \"&lt;strong&gt;Ponto de Partida&lt;\/strong&gt;\"\n          });\n \n          map.marker(routePoints[routePoints.length - 1], {\n               popup: \"&lt;strong&gt;Ponto de Chegada&lt;\/strong&gt;\"\n          });\n    &lt;\/script&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This example shows the result of a route between 2 points near Avenida Paulista in the city of S\u00e3o Paulo. In the variable apiKey, add your key received from Maplink. The variable map is associated with the class MaplinkMap and contains the properties of the map, such as div where it will be initialized. In [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[169],"tags":[],"class_list":["post-2808","post","type-post","status-publish","format-standard","hentry","category-map-display-en"],"acf":[],"_links":{"self":[{"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/posts\/2808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/comments?post=2808"}],"version-history":[{"count":1,"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/posts\/2808\/revisions"}],"predecessor-version":[{"id":2809,"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/posts\/2808\/revisions\/2809"}],"wp:attachment":[{"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/media?parent=2808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/categories?post=2808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developers.maplink.global\/en\/wp-json\/wp\/v2\/tags?post=2808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}