如何在Go客户端中使用Google Maps服务的Directions响应?

huangapple go评论132阅读模式
英文:

How to use Directions response in the Go client for Google Maps Services?

问题

使用googlemaps.github.io/maps在Go中获取方向时,响应是一个maps.Route数组。是否有办法将此响应转换为JavaScript的google.maps.DirectionsRenderer()可以读取的内容?这样做的目的是通过Go服务器获取方向并将该数据分发到多个平台。欢迎对如何将此数据转换为可视化地图的任何建议。

Go代码:

  1. package main
  2. import (
  3. "log"
  4. "googlemaps.github.io/maps"
  5. "github.com/kr/pretty"
  6. "golang.org/x/net/context"
  7. )
  8. func checkForError(err error) {
  9. if err != nil{
  10. log.Fatal(err)
  11. }
  12. }
  13. func main() {
  14. c, err := maps.NewClient(maps.WithAPIKey("myapikey"))
  15. checkForError(err)
  16. r := &maps.DirectionsRequest{
  17. Origin: "Hollywood, FL",
  18. Destination: "Davie, FL",
  19. }
  20. resp, _, err := c.Directions(context.Background(), r)
  21. checkForError(err)
  22. // render :=
  23. pretty.Println(resp)
  24. }

输出:

  1. []maps.Route{
  2. {
  3. Summary: "I-95 N and I-595 W",
  4. Legs: {
  5. &maps.Leg{
  6. Steps: {
  7. &maps.Step{
  8. HTMLInstructions: "Head <b>east</b> on <b>Hollywood Blvd</b> toward <b>S Dixie Hwy</b>",
  9. Distance: maps.Distance{HumanReadable:"217 ft", Meters:66},
  10. Duration: 23000000000,
  11. StartLocation: maps.LatLng{Lat:26.0112983, Lng:-80.1494921},
  12. EndLocation: maps.LatLng{Lat:26.0113264, Lng:-80.14883689999999},
  13. Polyline: maps.Polyline{Points:"siw}CheehN?e@Cq@Ai@"},
  14. Steps: nil,
  15. TransitDetails: (*maps.TransitDetails)(nil),
  16. TravelMode: "DRIVING",
  17. },
  18. &maps.Step{
  19. HTMLInstructions: "Make a <b>U-turn</b> at <b>S 21st Ave</b>",
  20. Distance: maps.Distance{HumanReadable:"0.6 mi", Meters:886},
  21. Duration: 90000000000,
  22. StartLocation: maps.LatLng{Lat:26.0113264, Lng:-80.14883689999999},
  23. EndLocation: maps.LatLng{Lat:26.0111533, Lng:-80.1575536},
  24. Polyline: maps.Polyline{Points:"yiw}CfaehNU??h@?r@BpAJVDfFHlOBfDDlCB|C@z@H~F"},
  25. Steps: nil,
  26. TransitDetails: (*maps.TransitDetails)(nil),
  27. TravelMode: "DRIVING",
  28. },
  29. &maps.Step{
  30. HTMLInstructions: "At the traffic circle, take the <b>3rd</b> exit and stay on <b>Hollywood Blvd</b>",
  31. Distance: maps.Distance{HumanReadable:"0.6 mi", Meters:937},
  32. Duration: 148000000000,
  33. StartLocation: maps.LatLng{Lat:26.0111533, Lng:-80.1575536},
  34. EndLocation: maps.LatLng{Lat:26.011037, Lng:-80.16587369999999},
  35. Polyline: maps.Polyline{Points:"uhw}CtwfhNGJAB?H?D?J?FAD?DCDCDCDSNUD]N_@XY\\Ub@GRGPIh@Ch@Bd@BJDXN`@DFLVVZ\\T\\P`@JNJHFFHBFBN@F?JBpB?d@@`ABpD@zB?nAB`C@bB@fAAt@AlA"},
  36. Steps: nil,
  37. TransitDetails: (*maps.TransitDetails)(nil),
  38. TravelMode: "DRIVING",
  39. },
  40. &maps.Step{
  41. HTMLInstructions: "Turn <b>right</b> to merge onto <b>I-95 N</b> toward <b>W Palm Beach</b>",
  42. Distance: maps.Distance{HumanReadable:"4.4 mi", Meters:7063},
  43. Duration: 277000000000,
  44. StartLocation: maps.LatLng{Lat:26.011037, Lng:-80.16587369999999},
  45. EndLocation: maps.LatLng{Lat:26.0732058, Lng:-80.1671851},
  46. Polyline: maps.Polyline{Points:"_hw}CtkhhNKVCHEJGJCBEBEBIBQDkBB_BJq@DkBR_Ff@_CT[DM@IBGFKJy@FyAFuAB_CD_B@U@cCBE?A?}BByQLqBA{BGuBQeBQyAQo@KoBc@aBa@sA]iHyBa@MoA[wBm@g@K_Ds@cB]aB[eB[qAScBU{BWMCWCsBWg@G}Ks@cHe@aQkA{CUeCOyCSsE[wDW{CSsKu@qAIEA_@COAA?gBM_@Co@E[Ck@CUAs@E]AWA]A]?q@AU?a@?O?Y?kA?s@Bk@@o@Bm@@wEPcKZc@@w@BiAFi@Bq@Dw@Hk@FoBRw@JSD[DmAR}@P}Dt@oCh@yFdAgB\\A@g@HIBA?eCd@cDn@y@Ns@NiB\\_ARu@LaBZyDt@qCh@}Bf@oDx@sBf@}A`@qAZcBb@aBb@qEpA"},
  47. Steps: nil,
  48. TransitDetails: (*maps.TransitDetails)(nil),
  49. TravelMode: "DRIVING",
  50. },
  51. &maps.Step{
  52. HTMLInstructions: "Take exit <b>24</b> for <b>Interstate 595</b> toward <b>Port Everglades</b>/<b>Ft Laud-Hlwd</b>/<b>International Airport</b>",
  53. Distance: maps.Distance{HumanReadable:"0.3 mi", Meters:416},
  54. Duration: 17000000000,
  55. StartLocation: maps.LatLng{Lat:26.0732058, Lng:-80.1671851},
  56. EndLocation: maps.LatLng{Lat:26.0768262, Lng:-80.1680758},
  57. Polyline: maps.Polyline{Points:"qlc~C|shhNKIAAAAA?C?E?E?A?MBc@H_@FqB^uAVoAT{@Na@F[Hi@HYFyAXm@L"},
  58. Steps: nil,
  59. TransitDetails: (*maps.TransitDetails)(nil),
  60. TravelMode: "DRIVING",
  61. },
  62. &maps.Step{
  63. HTMLInstructions: "Keep <b>left</b> at the fork, follow signs for <b>I-595 W</b>/<b>I-75</b>/<b>Florida's Turnpike</b> and merge onto <b>I-595 W</b>",
  64. Distance: maps.Distance{HumanReadable:"4.4 mi", Meters:7161},
  65. Duration: 255000000000,
  66. StartLocation: maps.LatLng{Lat:26.0768262, Lng:-80.1680758},
  67. EndLocation: maps.LatLng{Lat:26.0947648, Lng:-80.2317655},
  68. Polyline: maps.Polyline{Points:"ecd~CnyhhN[H[D_@Dm@FWBMBU@u@D_@@]@q@@W?]?MAU?[AYAQAe@C_@CWAk@CWAUAUAM?e@?W@Q@WBSBQBI@KBMBUHOFSFWNMHC@A@MHa@ZIFGF]`@IN[f@_@|@IVGT?BEREPCRALAHAF?BAB?FAJ?RAL?F?\\?F?D?N?RDlABn@Bx@@r@@t@@t@AV?h@A`@Ap@Cb@AZ?N?LATCh@CZ?@?@?@@@?@?@@BDFMhBIlAKdBGt@[rEe@zHAFk@vIE`@C`@UlDSbD?FMbECh@A|@C|A?`ACtEDxLD~PBvFDbE@vB?tF?xB@z@ClA?X?@?DG|BGx@IjAGx@Er@MtAMlAMdA[rBQhAUjA[zAWfA[vAYbAc@zAkAtCKXSj@wAhDiC`GiBdE_@|@]x@s@jBs@lBsAnDoAhEw@vCe@xB{@rD[nAsDjS]hBOn@e@~Bc@zBo@rCUpASfAu@fFUjBIj@MhAKp@S|ASzAS`BIv@]nCMbA_@bCQhAAF?FO~@y@zFeAbHyAtJ"},
  69. Steps: nil,
  70. TransitDetails: (*maps.TransitDetails)(nil),
  71. TravelMode: "DRIVING",
  72. },
  73. &maps.Step{
  74. HTMLInstructions: "Take exit <b>6</b> toward <b>FL-817</b>/<b>University Dr</b>",
  75. Distance: maps.Distance{HumanReadable:"0.4 mi", Meters:566},
  76. Duration: 20000000000,
  77. StartLocation: maps.LatLng{Lat:26.0947648, Lng:-80.2317655},
  78. EndLocation: maps.LatLng{Lat:26.0963976, Lng:-80.2371076},
  79. Polyline: maps.Polyline{Points:"gsg~CpguhNM\\Ot@qBfKs@tD{@nEKd@S|@Id@Kj@?@ABABMH"},
  80. Steps: nil,
  81. TransitDetails: (*maps.TransitDetails)(nil),
  82. TravelMode: "DRIVING",
  83. },
  84. &maps.Step{
  85. HTMLInstructions: "Merge onto <b>FL-84 W</b>",
  86. Distance: maps.Distance{HumanReadable:"0.8 mi", Meters:1365},
  87. Duration: 96000000000,
  88. StartLocation: maps.LatLng{Lat:26.0963976, Lng:-80.2371076},
  89. EndLocation: maps.LatLng{Lat:26.0994367, Lng:-80.25034819999999},
  90. Polyline: maps.Polyline{Points:"o}g~C|hvhNq@~EG`@_@`C_@jCWrBc@dDi@zDyAnJUvAM|@WnBMz@I|@OlAQ|AWrBQ|AKv@SxAWzASpAUnAYpAI`@"},
  91. Steps: nil,
  92. TransitDetails: (*maps.TransitDetails)(nil),
  93. TravelMode: "DRIVING",
  94. },
  95. &maps.Step{
  96. HTMLInstructions: "Turn <b>left</b> onto <b>S University Dr</b>",
  97. Distance: maps.Distance{HumanReadable:"1.7 mi", Meters:2808},
  98. Duration: 279000000000,
  99. StartLocation: maps.LatLng{Lat:26.0994367, Lng:-80.25034819999999},
  100. EndLocation: maps.LatLng{Lat:26.07466, Lng:-80.25254079999999},
  101. Polyline: maps.Polyline{Points:"oph~Ct{xhNKf@t@ND@h@Hd@JRBD@bBZfANl@Jx@JtALr@HjBLd@@pBJR@~BDT?z@AhBAt@A`CCfAArAC~@AfAAfBETA~GIlBCvHK|EGbFIr@AvDGR?jB?dC?N?pCDpCLl@FlBRPBl@Fh@HxCf@hGpAn@NzB`@VBx@LtAN~@Ht@FrAJ"},
  102. Steps: nil,
  103. TransitDetails: (*maps.TransitDetails)(nil),
  104. TravelMode: "DRIVING",
  105. },
  106. &maps.Step{
  107. HTMLInstructions: "Make a <b>U-turn</b><div style=\"font-size:0.9em\">Destination will be on the left</div>",
  108. Distance: maps.Distance{HumanReadable:"0.2 mi", Meters:242},
  109. Duration: 38000000000,
  110. StartLocation: maps.LatLng{Lat:26.07466, Lng:-80.25254079999999},
  111. EndLocation: maps.LatLng{Lat:26.0765145, Lng:-80.25211829999999},
  112. Polyline: maps.Polyline{Points:"suc~CjiyhN@i@g@EwAIC?sAMYCm@Iy@M[E@T"},
  113. Steps: nil,
  114. TransitDetails: (*maps.TransitDetails)(nil),
  115. TravelMode: "DRIVING",
  116. },
  117. },
  118. Distance: maps.Distance{HumanReadable:"13.4 mi", Meters:21510},
  119. Duration: 1243000000000,
  120. DurationInTraffic: 0,
  121. ArrivalTime: time.Time{},
  122. DepartureTime: time.Time{},
  123. StartLocation: maps.LatLng{Lat:26.0112983, Lng:-80.1494921},
  124. EndLocation: maps.LatLng{Lat:26.0765145, Lng:-80.25211829999999},
  125. StartAddress: "Hollywood, FL, USA",
  126. EndAddress: "Davie, FL, USA",
  127. },
  128. },
  129. WaypointOrder: {},
  130. OverviewPolyline: maps.Polyline{Points:"siw}CheehNCwAAi@U??|ABpAJVNtVHtHDxEH~FGJAL?PEXGJSNUD]N_@XY\\Ub@Od@Ih@Ch@Fp@Tz@R^t@p@\\P`@JXRJPDVDdFH~NBjDCbC]x@YNQDkBBqCPgNvAWDSRsCNuEH_GF_CByQLqBA{BGuBQ_Ec@_Do@uD_AkIgCgEiAgE_AeEy@wDo@_Fm@yC_@eM{@eZqBoSuAqZsBsE[sCMeCEaB?{EHmTp@}ETkGp@{Dp@oTbEmMdCaIzAkI~AmH`BgKhCsHtBMKMAy@L{M`C}Dx@aCVyBLeCByAEoBKoBI}ABgAL_AX}@b@{@n@e@h@e@v@i@tAGXQfACTEfBDvBJrEAxCG`CInBBHDFMhBUrDkAlQkAhQSjDQlFIrLJx^HzLBbPChBGbCQdCMlB[bDi@xDg@tCs@bDu@zCc@zAkAtC_@dAkJnTyEbMgC`JaBlH[nAsDjSm@xCoC`NiAnH_@vCaAtHiAlJs@|EiAzH_DxS]rAeD|PeBxIOt@MHq@~Eg@bDeC`RuCtRy@dHiAbJk@lDo@`DUhAz@PhBZjDj@fBVhCVpCNdCLtCD|IIbHIjOUlX_@jEGpF?`DDpCLl@F~BVvAPxCf@hGpAjDp@pAPtCXhCR@i@g@E{AImBQgBW[E@T"},
  131. Bounds: maps.LatLngBounds{
  132. NorthEast: maps.LatLng{Lat:26.0994988, Lng:-80.14883689999999},
  133. SouthWest: maps.LatLng{Lat:26.0110222, Lng:-80.25254079999999},
  134. },
  135. Copyrights: "Map data ©2016 Google",
  136. Warnings: {},
  137. },
  138. }
英文:

When getting directions using "googlemaps.github.io/maps" in Go, the response is an array of maps.Route . Is there a way to turn this response into something readable by javascript's google.maps.DirectionsRenderer(); , the purpose of this is to get the directions with a go server and distribute that data into multiple platforms. Any suggestions about how to transform this data into a visual map are welcome.

Go code:

  1. package main
  2. import (
  3. &quot;log&quot;
  4. &quot;googlemaps.github.io/maps&quot;
  5. &quot;github.com/kr/pretty&quot;
  6. &quot;golang.org/x/net/context&quot;
  7. )
  8. func checkForError(err error) {
  9. if err != nil{
  10. log.Fatal(err)
  11. }
  12. }
  13. func main() {
  14. c, err := maps.NewClient(maps.WithAPIKey(&quot;myapikey&quot;))
  15. checkForError(err)
  16. r := &amp;maps.DirectionsRequest{
  17. Origin: &quot;Hollywood, FL&quot;,
  18. Destination: &quot;Davie, FL&quot;,
  19. }
  20. resp, _, err := c.Directions(context.Background(), r)
  21. checkForError(err)
  22. // render :=
  23. pretty.Println(resp)
  24. }

Output:

  1. []maps.Route{
  2. {
  3. Summary: &quot;I-95 N and I-595 W&quot;,
  4. Legs: {
  5. &amp;maps.Leg{
  6. Steps: {
  7. &amp;maps.Step{
  8. HTMLInstructions: &quot;Head &lt;b&gt;east&lt;/b&gt; on &lt;b&gt;Hollywood Blvd&lt;/b&gt; toward &lt;b&gt;S Dixie Hwy&lt;/b&gt;&quot;,
  9. Distance: maps.Distance{HumanReadable:&quot;217 ft&quot;, Meters:66},
  10. Duration: 23000000000,
  11. StartLocation: maps.LatLng{Lat:26.0112983, Lng:-80.1494921},
  12. EndLocation: maps.LatLng{Lat:26.0113264, Lng:-80.14883689999999},
  13. Polyline: maps.Polyline{Points:&quot;siw}CheehN?e@Cq@Ai@&quot;},
  14. Steps: nil,
  15. TransitDetails: (*maps.TransitDetails)(nil),
  16. TravelMode: &quot;DRIVING&quot;,
  17. },
  18. &amp;maps.Step{
  19. HTMLInstructions: &quot;Make a &lt;b&gt;U-turn&lt;/b&gt; at &lt;b&gt;S 21st Ave&lt;/b&gt;&quot;,
  20. Distance: maps.Distance{HumanReadable:&quot;0.6 mi&quot;, Meters:886},
  21. Duration: 90000000000,
  22. StartLocation: maps.LatLng{Lat:26.0113264, Lng:-80.14883689999999},
  23. EndLocation: maps.LatLng{Lat:26.0111533, Lng:-80.1575536},
  24. Polyline: maps.Polyline{Points:&quot;yiw}CfaehNU??h@?r@BpAJVDfFHlOBfDDlCB|C@z@H~F&quot;},
  25. Steps: nil,
  26. TransitDetails: (*maps.TransitDetails)(nil),
  27. TravelMode: &quot;DRIVING&quot;,
  28. },
  29. &amp;maps.Step{
  30. HTMLInstructions: &quot;At the traffic circle, take the &lt;b&gt;3rd&lt;/b&gt; exit and stay on &lt;b&gt;Hollywood Blvd&lt;/b&gt;&quot;,
  31. Distance: maps.Distance{HumanReadable:&quot;0.6 mi&quot;, Meters:937},
  32. Duration: 148000000000,
  33. StartLocation: maps.LatLng{Lat:26.0111533, Lng:-80.1575536},
  34. EndLocation: maps.LatLng{Lat:26.011037, Lng:-80.16587369999999},
  35. Polyline: maps.Polyline{Points:&quot;uhw}CtwfhNGJAB?H?D?J?FAD?DCDCDCDSNUD]N_@XY\\Ub@GRGPIh@Ch@Bd@BJDXN`@DFLVVZ\\T\\P`@JNJHFFHBFBN@F?JBpB?d@@`ABpD@zB?nAB`C@bB@fAAt@AlA&quot;},
  36. Steps: nil,
  37. TransitDetails: (*maps.TransitDetails)(nil),
  38. TravelMode: &quot;DRIVING&quot;,
  39. },
  40. &amp;maps.Step{
  41. HTMLInstructions: &quot;Turn &lt;b&gt;right&lt;/b&gt; to merge onto &lt;b&gt;I-95 N&lt;/b&gt; toward &lt;b&gt;W Palm Beach&lt;/b&gt;&quot;,
  42. Distance: maps.Distance{HumanReadable:&quot;4.4 mi&quot;, Meters:7063},
  43. Duration: 277000000000,
  44. StartLocation: maps.LatLng{Lat:26.011037, Lng:-80.16587369999999},
  45. EndLocation: maps.LatLng{Lat:26.0732058, Lng:-80.1671851},
  46. Polyline: maps.Polyline{Points:&quot;_hw}CtkhhNKVCHEJGJCBEBEBIBQDkBB_BJq@DkBR_Ff@_CT[DM@IBGFKJy@FyAFuAB_CD_B@U@cCBE?A?}BByQLqBA{BGuBQeBQyAQo@KoBc@aBa@sA]iHyBa@MoA[wBm@g@K_Ds@cB]aB[eB[qAScBU{BWMCWCsBWg@G}Ks@cHe@aQkA{CUeCOyCSsE[wDW{CSsKu@qAIEA_@COAA?gBM_@Co@E[Ck@CUAs@E]AWA]A]?q@AU?a@?O?Y?kA?s@Bk@@o@Bm@@wEPcKZc@@w@BiAFi@Bq@Dw@Hk@FoBRw@JSD[DmAR}@P}Dt@oCh@yFdAgB\\A@g@HIBA?eCd@cDn@y@Ns@NiB\\_ARu@LaBZyDt@qCh@}Bf@oDx@sBf@}A`@qAZcBb@aBb@qEpA&quot;},
  47. Steps: nil,
  48. TransitDetails: (*maps.TransitDetails)(nil),
  49. TravelMode: &quot;DRIVING&quot;,
  50. },
  51. &amp;maps.Step{
  52. HTMLInstructions: &quot;Take exit &lt;b&gt;24&lt;/b&gt; for &lt;b&gt;Interstate 595&lt;/b&gt; toward &lt;b&gt;Port Everglades&lt;/b&gt;/&lt;b&gt;Ft Laud-Hlwd&lt;/b&gt;/&lt;b&gt;International Airport&lt;/b&gt;&quot;,
  53. Distance: maps.Distance{HumanReadable:&quot;0.3 mi&quot;, Meters:416},
  54. Duration: 17000000000,
  55. StartLocation: maps.LatLng{Lat:26.0732058, Lng:-80.1671851},
  56. EndLocation: maps.LatLng{Lat:26.0768262, Lng:-80.1680758},
  57. Polyline: maps.Polyline{Points:&quot;qlc~C|shhNKIAAAAA?C?E?E?A?MBc@H_@FqB^uAVoAT{@Na@F[Hi@HYFyAXm@L&quot;},
  58. Steps: nil,
  59. TransitDetails: (*maps.TransitDetails)(nil),
  60. TravelMode: &quot;DRIVING&quot;,
  61. },
  62. &amp;maps.Step{
  63. HTMLInstructions: &quot;Keep &lt;b&gt;left&lt;/b&gt; at the fork, follow signs for &lt;b&gt;I-595 W&lt;/b&gt;/&lt;b&gt;I-75&lt;/b&gt;/&lt;b&gt;Florida&#39;s Turnpike&lt;/b&gt; and merge onto &lt;b&gt;I-595 W&lt;/b&gt;&quot;,
  64. Distance: maps.Distance{HumanReadable:&quot;4.4 mi&quot;, Meters:7161},
  65. Duration: 255000000000,
  66. StartLocation: maps.LatLng{Lat:26.0768262, Lng:-80.1680758},
  67. EndLocation: maps.LatLng{Lat:26.0947648, Lng:-80.2317655},
  68. Polyline: maps.Polyline{Points:&quot;ecd~CnyhhN[H[D_@Dm@FWBMBU@u@D_@@]@q@@W?]?MAU?[AYAQAe@C_@CWAk@CWAUAUAM?e@?W@Q@WBSBQBI@KBMBUHOFSFWNMHC@A@MHa@ZIFGF]`@IN[f@_@|@IVGT?BEREPCRALAHAF?BAB?FAJ?RAL?F?\\?F?D?N?RDlABn@Bx@@r@@t@@t@AV?h@A`@Ap@Cb@AZ?N?LATCh@CZ?@?@?@@@?@?@@BDFMhBIlAKdBGt@[rEe@zHAFk@vIE`@C`@UlDSbD?FMbECh@A|@C|A?`ACtEDxLD~PBvFDbE@vB?tF?xB@z@ClA?X?@?DG|BGx@IjAGx@Er@MtAMlAMdA[rBQhAUjA[zAWfA[vAYbAc@zAkAtCKXSj@wAhDiC`GiBdE_@|@]x@s@jBs@lBsAnDoAhEw@vCe@xB{@rD[nAsDjS]hBOn@e@~Bc@zBo@rCUpASfAu@fFUjBIj@MhAKp@S|ASzAS`BIv@]nCMbA_@bCQhAAF?FO~@y@zFeAbHyAtJ&quot;},
  69. Steps: nil,
  70. TransitDetails: (*maps.TransitDetails)(nil),
  71. TravelMode: &quot;DRIVING&quot;,
  72. },
  73. &amp;maps.Step{
  74. HTMLInstructions: &quot;Take exit &lt;b&gt;6&lt;/b&gt; toward &lt;b&gt;FL-817&lt;/b&gt;/&lt;b&gt;University Dr&lt;/b&gt;&quot;,
  75. Distance: maps.Distance{HumanReadable:&quot;0.4 mi&quot;, Meters:566},
  76. Duration: 20000000000,
  77. StartLocation: maps.LatLng{Lat:26.0947648, Lng:-80.2317655},
  78. EndLocation: maps.LatLng{Lat:26.0963976, Lng:-80.2371076},
  79. Polyline: maps.Polyline{Points:&quot;gsg~CpguhNM\\Ot@qBfKs@tD{@nEKd@S|@Id@Kj@?@ABABMH&quot;},
  80. Steps: nil,
  81. TransitDetails: (*maps.TransitDetails)(nil),
  82. TravelMode: &quot;DRIVING&quot;,
  83. },
  84. &amp;maps.Step{
  85. HTMLInstructions: &quot;Merge onto &lt;b&gt;FL-84 W&lt;/b&gt;&quot;,
  86. Distance: maps.Distance{HumanReadable:&quot;0.8 mi&quot;, Meters:1365},
  87. Duration: 96000000000,
  88. StartLocation: maps.LatLng{Lat:26.0963976, Lng:-80.2371076},
  89. EndLocation: maps.LatLng{Lat:26.0994367, Lng:-80.25034819999999},
  90. Polyline: maps.Polyline{Points:&quot;o}g~C|hvhNq@~EG`@_@`C_@jCWrBc@dDi@zDyAnJUvAM|@WnBMz@I|@OlAQ|AWrBQ|AKv@SxAWzASpAUnAYpAI`@&quot;},
  91. Steps: nil,
  92. TransitDetails: (*maps.TransitDetails)(nil),
  93. TravelMode: &quot;DRIVING&quot;,
  94. },
  95. &amp;maps.Step{
  96. HTMLInstructions: &quot;Turn &lt;b&gt;left&lt;/b&gt; onto &lt;b&gt;S University Dr&lt;/b&gt;&quot;,
  97. Distance: maps.Distance{HumanReadable:&quot;1.7 mi&quot;, Meters:2808},
  98. Duration: 279000000000,
  99. StartLocation: maps.LatLng{Lat:26.0994367, Lng:-80.25034819999999},
  100. EndLocation: maps.LatLng{Lat:26.07466, Lng:-80.25254079999999},
  101. Polyline: maps.Polyline{Points:&quot;oph~Ct{xhNKf@t@ND@h@Hd@JRBD@bBZfANl@Jx@JtALr@HjBLd@@pBJR@~BDT?z@AhBAt@A`CCfAArAC~@AfAAfBETA~GIlBCvHK|EGbFIr@AvDGR?jB?dC?N?pCDpCLl@FlBRPBl@Fh@HxCf@hGpAn@NzB`@VBx@LtAN~@Ht@FrAJ&quot;},
  102. Steps: nil,
  103. TransitDetails: (*maps.TransitDetails)(nil),
  104. TravelMode: &quot;DRIVING&quot;,
  105. },
  106. &amp;maps.Step{
  107. HTMLInstructions: &quot;Make a &lt;b&gt;U-turn&lt;/b&gt;&lt;div style=\&quot;font-size:0.9em\&quot;&gt;Destination will be on the left&lt;/div&gt;&quot;,
  108. Distance: maps.Distance{HumanReadable:&quot;0.2 mi&quot;, Meters:242},
  109. Duration: 38000000000,
  110. StartLocation: maps.LatLng{Lat:26.07466, Lng:-80.25254079999999},
  111. EndLocation: maps.LatLng{Lat:26.0765145, Lng:-80.25211829999999},
  112. Polyline: maps.Polyline{Points:&quot;suc~CjiyhN@i@g@EwAIC?sAMYCm@Iy@M[E@T&quot;},
  113. Steps: nil,
  114. TransitDetails: (*maps.TransitDetails)(nil),
  115. TravelMode: &quot;DRIVING&quot;,
  116. },
  117. },
  118. Distance: maps.Distance{HumanReadable:&quot;13.4 mi&quot;, Meters:21510},
  119. Duration: 1243000000000,
  120. DurationInTraffic: 0,
  121. ArrivalTime: time.Time{},
  122. DepartureTime: time.Time{},
  123. StartLocation: maps.LatLng{Lat:26.0112983, Lng:-80.1494921},
  124. EndLocation: maps.LatLng{Lat:26.0765145, Lng:-80.25211829999999},
  125. StartAddress: &quot;Hollywood, FL, USA&quot;,
  126. EndAddress: &quot;Davie, FL, USA&quot;,
  127. },
  128. },
  129. WaypointOrder: {},
  130. OverviewPolyline: maps.Polyline{Points:&quot;siw}CheehNCwAAi@U??|ABpAJVNtVHtHDxEH~FGJAL?PEXGJSNUD]N_@XY\\Ub@Od@Ih@Ch@Fp@Tz@R^t@p@\\P`@JXRJPDVDdFH~NBjDCbC]x@YNQDkBBqCPgNvAWDSRsCNuEH_GF_CByQLqBA{BGuBQ_Ec@_Do@uD_AkIgCgEiAgE_AeEy@wDo@_Fm@yC_@eM{@eZqBoSuAqZsBsE[sCMeCEaB?{EHmTp@}ETkGp@{Dp@oTbEmMdCaIzAkI~AmH`BgKhCsHtBMKMAy@L{M`C}Dx@aCVyBLeCByAEoBKoBI}ABgAL_AX}@b@{@n@e@h@e@v@i@tAGXQfACTEfBDvBJrEAxCG`CInBBHDFMhBUrDkAlQkAhQSjDQlFIrLJx^HzLBbPChBGbCQdCMlB[bDi@xDg@tCs@bDu@zCc@zAkAtC_@dAkJnTyEbMgC`JaBlH[nAsDjSm@xCoC`NiAnH_@vCaAtHiAlJs@|EiAzH_DxS]rAeD|PeBxIOt@MHq@~Eg@bDeC`RuCtRy@dHiAbJk@lDo@`DUhAz@PhBZjDj@fBVhCVpCNdCLtCD|IIbHIjOUlX_@jEGpF?`DDpCLl@F~BVvAPxCf@hGpAjDp@pAPtCXhCR@i@g@E{AImBQgBW[E@T&quot;},
  131. Bounds: maps.LatLngBounds{
  132. NorthEast: maps.LatLng{Lat:26.0994988, Lng:-80.14883689999999},
  133. SouthWest: maps.LatLng{Lat:26.0110222, Lng:-80.25254079999999},
  134. },
  135. Copyrights: &quot;Map data &#169;2016 Google&quot;,
  136. Warnings: {},
  137. },
  138. }

答案1

得分: 1

那个JSON输出是一个DirectionsResult对象,它通过DirectionsRendererOptions直接传递给你所询问的DirectionsRenderer()构造函数。

如果你想将其转换为Go语言,你可以使用相同的结构体将其转换回来,以供寻找DirectionsResult对象的消费者使用。

英文:

That JSON output is a DirectionsResult object, which is passed in through the DirectionsRendererOptions directly to the DirectionsRenderer() constructor you're asking about.

If you're trying to marshal it in to Go you can use the same structs to marshal it back out for consumers that are looking for a DirectionsResult object.

huangapple
  • 本文由 发表于 2016年4月5日 02:42:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/36410397.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定