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

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

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代码:

package main

import (
    "log"

    "googlemaps.github.io/maps"
    "github.com/kr/pretty"
    "golang.org/x/net/context"
)

func checkForError(err error) {
    if err != nil{
        log.Fatal(err)
    }
}

func main() {
    c, err := maps.NewClient(maps.WithAPIKey("myapikey"))
    checkForError(err)

    r := &maps.DirectionsRequest{
        Origin:      "Hollywood, FL",
        Destination: "Davie, FL",
    }

    resp, _, err := c.Directions(context.Background(), r)
    checkForError(err)

    // render := 

    pretty.Println(resp)
}

输出:

[]maps.Route{
{
Summary: "I-95 N and I-595 W",
Legs:    {
&maps.Leg{
Steps: {
&maps.Step{
HTMLInstructions: "Head <b>east</b> on <b>Hollywood Blvd</b> toward <b>S Dixie Hwy</b>",
Distance:         maps.Distance{HumanReadable:"217 ft", Meters:66},
Duration:         23000000000,
StartLocation:    maps.LatLng{Lat:26.0112983, Lng:-80.1494921},
EndLocation:      maps.LatLng{Lat:26.0113264, Lng:-80.14883689999999},
Polyline:         maps.Polyline{Points:"siw}CheehN?e@Cq@Ai@"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
&maps.Step{
HTMLInstructions: "Make a <b>U-turn</b> at <b>S 21st Ave</b>",
Distance:         maps.Distance{HumanReadable:"0.6 mi", Meters:886},
Duration:         90000000000,
StartLocation:    maps.LatLng{Lat:26.0113264, Lng:-80.14883689999999},
EndLocation:      maps.LatLng{Lat:26.0111533, Lng:-80.1575536},
Polyline:         maps.Polyline{Points:"yiw}CfaehNU??h@?r@BpAJVDfFHlOBfDDlCB|C@z@H~F"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
&maps.Step{
HTMLInstructions: "At the traffic circle, take the <b>3rd</b> exit and stay on <b>Hollywood Blvd</b>",
Distance:         maps.Distance{HumanReadable:"0.6 mi", Meters:937},
Duration:         148000000000,
StartLocation:    maps.LatLng{Lat:26.0111533, Lng:-80.1575536},
EndLocation:      maps.LatLng{Lat:26.011037, Lng:-80.16587369999999},
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"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
&maps.Step{
HTMLInstructions: "Turn <b>right</b> to merge onto <b>I-95 N</b> toward <b>W Palm Beach</b>",
Distance:         maps.Distance{HumanReadable:"4.4 mi", Meters:7063},
Duration:         277000000000,
StartLocation:    maps.LatLng{Lat:26.011037, Lng:-80.16587369999999},
EndLocation:      maps.LatLng{Lat:26.0732058, Lng:-80.1671851},
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"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
&maps.Step{
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>",
Distance:         maps.Distance{HumanReadable:"0.3 mi", Meters:416},
Duration:         17000000000,
StartLocation:    maps.LatLng{Lat:26.0732058, Lng:-80.1671851},
EndLocation:      maps.LatLng{Lat:26.0768262, Lng:-80.1680758},
Polyline:         maps.Polyline{Points:"qlc~C|shhNKIAAAAA?C?E?E?A?MBc@H_@FqB^uAVoAT{@Na@F[Hi@HYFyAXm@L"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
&maps.Step{
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>",
Distance:         maps.Distance{HumanReadable:"4.4 mi", Meters:7161},
Duration:         255000000000,
StartLocation:    maps.LatLng{Lat:26.0768262, Lng:-80.1680758},
EndLocation:      maps.LatLng{Lat:26.0947648, Lng:-80.2317655},
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"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
&maps.Step{
HTMLInstructions: "Take exit <b>6</b> toward <b>FL-817</b>/<b>University Dr</b>",
Distance:         maps.Distance{HumanReadable:"0.4 mi", Meters:566},
Duration:         20000000000,
StartLocation:    maps.LatLng{Lat:26.0947648, Lng:-80.2317655},
EndLocation:      maps.LatLng{Lat:26.0963976, Lng:-80.2371076},
Polyline:         maps.Polyline{Points:"gsg~CpguhNM\\Ot@qBfKs@tD{@nEKd@S|@Id@Kj@?@ABABMH"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
&maps.Step{
HTMLInstructions: "Merge onto <b>FL-84 W</b>",
Distance:         maps.Distance{HumanReadable:"0.8 mi", Meters:1365},
Duration:         96000000000,
StartLocation:    maps.LatLng{Lat:26.0963976, Lng:-80.2371076},
EndLocation:      maps.LatLng{Lat:26.0994367, Lng:-80.25034819999999},
Polyline:         maps.Polyline{Points:"o}g~C|hvhNq@~EG`@_@`C_@jCWrBc@dDi@zDyAnJUvAM|@WnBMz@I|@OlAQ|AWrBQ|AKv@SxAWzASpAUnAYpAI`@"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
&maps.Step{
HTMLInstructions: "Turn <b>left</b> onto <b>S University Dr</b>",
Distance:         maps.Distance{HumanReadable:"1.7 mi", Meters:2808},
Duration:         279000000000,
StartLocation:    maps.LatLng{Lat:26.0994367, Lng:-80.25034819999999},
EndLocation:      maps.LatLng{Lat:26.07466, Lng:-80.25254079999999},
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"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
&maps.Step{
HTMLInstructions: "Make a <b>U-turn</b><div style=\"font-size:0.9em\">Destination will be on the left</div>",
Distance:         maps.Distance{HumanReadable:"0.2 mi", Meters:242},
Duration:         38000000000,
StartLocation:    maps.LatLng{Lat:26.07466, Lng:-80.25254079999999},
EndLocation:      maps.LatLng{Lat:26.0765145, Lng:-80.25211829999999},
Polyline:         maps.Polyline{Points:"suc~CjiyhN@i@g@EwAIC?sAMYCm@Iy@M[E@T"},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       "DRIVING",
},
},
Distance:          maps.Distance{HumanReadable:"13.4 mi", Meters:21510},
Duration:          1243000000000,
DurationInTraffic: 0,
ArrivalTime:       time.Time{},
DepartureTime:     time.Time{},
StartLocation:     maps.LatLng{Lat:26.0112983, Lng:-80.1494921},
EndLocation:       maps.LatLng{Lat:26.0765145, Lng:-80.25211829999999},
StartAddress:      "Hollywood, FL, USA",
EndAddress:        "Davie, FL, USA",
},
},
WaypointOrder:    {},
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"},
Bounds:           maps.LatLngBounds{
NorthEast: maps.LatLng{Lat:26.0994988, Lng:-80.14883689999999},
SouthWest: maps.LatLng{Lat:26.0110222, Lng:-80.25254079999999},
},
Copyrights: "Map data ©2016 Google",
Warnings:   {},
},
}
英文:

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:

package main
import (
&quot;log&quot;
&quot;googlemaps.github.io/maps&quot;
&quot;github.com/kr/pretty&quot;
&quot;golang.org/x/net/context&quot;
)
func checkForError(err error) {
if err != nil{
log.Fatal(err)
}
}
func main() {
c, err := maps.NewClient(maps.WithAPIKey(&quot;myapikey&quot;))
checkForError(err)
r := &amp;maps.DirectionsRequest{
Origin:      &quot;Hollywood, FL&quot;,
Destination: &quot;Davie, FL&quot;,
}
resp, _, err := c.Directions(context.Background(), r)
checkForError(err)
// render := 
pretty.Println(resp)
}

Output:

[]maps.Route{
{
Summary: &quot;I-95 N and I-595 W&quot;,
Legs:    {
&amp;maps.Leg{
Steps: {
&amp;maps.Step{
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;,
Distance:         maps.Distance{HumanReadable:&quot;217 ft&quot;, Meters:66},
Duration:         23000000000,
StartLocation:    maps.LatLng{Lat:26.0112983, Lng:-80.1494921},
EndLocation:      maps.LatLng{Lat:26.0113264, Lng:-80.14883689999999},
Polyline:         maps.Polyline{Points:&quot;siw}CheehN?e@Cq@Ai@&quot;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
&amp;maps.Step{
HTMLInstructions: &quot;Make a &lt;b&gt;U-turn&lt;/b&gt; at &lt;b&gt;S 21st Ave&lt;/b&gt;&quot;,
Distance:         maps.Distance{HumanReadable:&quot;0.6 mi&quot;, Meters:886},
Duration:         90000000000,
StartLocation:    maps.LatLng{Lat:26.0113264, Lng:-80.14883689999999},
EndLocation:      maps.LatLng{Lat:26.0111533, Lng:-80.1575536},
Polyline:         maps.Polyline{Points:&quot;yiw}CfaehNU??h@?r@BpAJVDfFHlOBfDDlCB|C@z@H~F&quot;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
&amp;maps.Step{
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;,
Distance:         maps.Distance{HumanReadable:&quot;0.6 mi&quot;, Meters:937},
Duration:         148000000000,
StartLocation:    maps.LatLng{Lat:26.0111533, Lng:-80.1575536},
EndLocation:      maps.LatLng{Lat:26.011037, Lng:-80.16587369999999},
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;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
&amp;maps.Step{
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;,
Distance:         maps.Distance{HumanReadable:&quot;4.4 mi&quot;, Meters:7063},
Duration:         277000000000,
StartLocation:    maps.LatLng{Lat:26.011037, Lng:-80.16587369999999},
EndLocation:      maps.LatLng{Lat:26.0732058, Lng:-80.1671851},
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;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
&amp;maps.Step{
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;,
Distance:         maps.Distance{HumanReadable:&quot;0.3 mi&quot;, Meters:416},
Duration:         17000000000,
StartLocation:    maps.LatLng{Lat:26.0732058, Lng:-80.1671851},
EndLocation:      maps.LatLng{Lat:26.0768262, Lng:-80.1680758},
Polyline:         maps.Polyline{Points:&quot;qlc~C|shhNKIAAAAA?C?E?E?A?MBc@H_@FqB^uAVoAT{@Na@F[Hi@HYFyAXm@L&quot;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
&amp;maps.Step{
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;,
Distance:         maps.Distance{HumanReadable:&quot;4.4 mi&quot;, Meters:7161},
Duration:         255000000000,
StartLocation:    maps.LatLng{Lat:26.0768262, Lng:-80.1680758},
EndLocation:      maps.LatLng{Lat:26.0947648, Lng:-80.2317655},
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;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
&amp;maps.Step{
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;,
Distance:         maps.Distance{HumanReadable:&quot;0.4 mi&quot;, Meters:566},
Duration:         20000000000,
StartLocation:    maps.LatLng{Lat:26.0947648, Lng:-80.2317655},
EndLocation:      maps.LatLng{Lat:26.0963976, Lng:-80.2371076},
Polyline:         maps.Polyline{Points:&quot;gsg~CpguhNM\\Ot@qBfKs@tD{@nEKd@S|@Id@Kj@?@ABABMH&quot;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
&amp;maps.Step{
HTMLInstructions: &quot;Merge onto &lt;b&gt;FL-84 W&lt;/b&gt;&quot;,
Distance:         maps.Distance{HumanReadable:&quot;0.8 mi&quot;, Meters:1365},
Duration:         96000000000,
StartLocation:    maps.LatLng{Lat:26.0963976, Lng:-80.2371076},
EndLocation:      maps.LatLng{Lat:26.0994367, Lng:-80.25034819999999},
Polyline:         maps.Polyline{Points:&quot;o}g~C|hvhNq@~EG`@_@`C_@jCWrBc@dDi@zDyAnJUvAM|@WnBMz@I|@OlAQ|AWrBQ|AKv@SxAWzASpAUnAYpAI`@&quot;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
&amp;maps.Step{
HTMLInstructions: &quot;Turn &lt;b&gt;left&lt;/b&gt; onto &lt;b&gt;S University Dr&lt;/b&gt;&quot;,
Distance:         maps.Distance{HumanReadable:&quot;1.7 mi&quot;, Meters:2808},
Duration:         279000000000,
StartLocation:    maps.LatLng{Lat:26.0994367, Lng:-80.25034819999999},
EndLocation:      maps.LatLng{Lat:26.07466, Lng:-80.25254079999999},
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;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
&amp;maps.Step{
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;,
Distance:         maps.Distance{HumanReadable:&quot;0.2 mi&quot;, Meters:242},
Duration:         38000000000,
StartLocation:    maps.LatLng{Lat:26.07466, Lng:-80.25254079999999},
EndLocation:      maps.LatLng{Lat:26.0765145, Lng:-80.25211829999999},
Polyline:         maps.Polyline{Points:&quot;suc~CjiyhN@i@g@EwAIC?sAMYCm@Iy@M[E@T&quot;},
Steps:            nil,
TransitDetails:   (*maps.TransitDetails)(nil),
TravelMode:       &quot;DRIVING&quot;,
},
},
Distance:          maps.Distance{HumanReadable:&quot;13.4 mi&quot;, Meters:21510},
Duration:          1243000000000,
DurationInTraffic: 0,
ArrivalTime:       time.Time{},
DepartureTime:     time.Time{},
StartLocation:     maps.LatLng{Lat:26.0112983, Lng:-80.1494921},
EndLocation:       maps.LatLng{Lat:26.0765145, Lng:-80.25211829999999},
StartAddress:      &quot;Hollywood, FL, USA&quot;,
EndAddress:        &quot;Davie, FL, USA&quot;,
},
},
WaypointOrder:    {},
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;},
Bounds:           maps.LatLngBounds{
NorthEast: maps.LatLng{Lat:26.0994988, Lng:-80.14883689999999},
SouthWest: maps.LatLng{Lat:26.0110222, Lng:-80.25254079999999},
},
Copyrights: &quot;Map data &#169;2016 Google&quot;,
Warnings:   {},
},
}

答案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:

确定