0
Goで「googlemaps.github.io/maps」を使用してルートを取得すると、レスポンスはマップの配列になります。ルート。このレスポンスをjavacriptのgoogle.maps.DirectionsRenderer();
で読み取り可能なものにする方法はありますか?これはGoサーバーで指示を取得し、そのデータを複数のプラットフォームに配布することです。このデータを視覚的な地図に変換する方法についてのご意見は大歓迎です。GoogleマップサービスのGoクライアントでDirections返信を使用するにはどうすればよいですか?
ゴーコード:
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}[email protected]@[email protected]"},
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}[email protected][email protected]|[email protected]@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][email protected]\\[email protected]@[email protected]@BJDXN`@DFLVVZ\\T\\P`@[email protected][email protected]@`[email protected]?nAB`[email protected]@[email protected]"},
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}[email protected][email protected]_CT[[email protected]@[email protected]@cCBE?A?}BByQLqBA{[email protected]@[email protected]][email protected][[email protected]@[email protected]]aB[eB[qAScBU{[email protected]}[email protected]@aQkA{CUeCOyCSsE[wDW{[email protected][email protected][email protected]@E[[email protected]@E]AWA]A][email protected][email protected][email protected]@@[email protected]@@[email protected]@[email protected]@[email protected]@[email protected]@JSD[DmAR}@P}[email protected]@yFdAgB\\[email protected]@[email protected]@[email protected]@NiB\\[email protected]@[email protected]}[email protected]@[email protected]}A`@[email protected]@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|[email protected][email protected]^uAVoAT{@[email protected][[email protected]@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[[email protected]@[email protected]@[email protected]@]@[email protected]@W?]?MAU?[[email protected][email protected]@[email protected][email protected]@[email protected]@[email protected]@ZIFGF]`@IN[[email protected][email protected]|@IVGT?BEREPCRALAHAF?BAB?FAJ?RAL?F?\\[email protected]@@[email protected]@[email protected]@[email protected][email protected]`@[email protected]@[email protected][email protected][email protected][email protected]@@[email protected][email protected]@[email protected][[email protected]@vIE`@C`@[email protected]|@C|A?`[email protected][email protected]@[email protected]?DG|[email protected]@[email protected][rBQhAUjA[zAWfA[[email protected]@wAhDiC`[email protected]|@][email protected]@[email protected]@[email protected]{@rD[nAsDjS][email protected]@[email protected]@[email protected]@[email protected]|ASzAS`[email protected]][email protected][email protected]@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\\[email protected]@tD{@[email protected]|@[email protected]@[email protected]"},
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|[email protected]~EG`@[email protected]`[email protected]@[email protected]|@[email protected]|@OlAQ|AWrBQ|[email protected]`@"},
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{[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected][email protected]@A`[email protected]~GIlBCvHK|[email protected][email protected]@[email protected]@[email protected]`@[email protected][email protected]@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:"[email protected]@[email protected][email protected]@M[[email protected]"},
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}[email protected]??|ABpAJVNtVHtHDxEH~FGJAL?PEXGJSNUD][email protected]\\[email protected]@[email protected]@[email protected]@R^[email protected]@\\P`@JXRJPDVDdFH~NBjDCbC][email protected]_GF_CByQLqBA{[email protected][email protected][email protected]@[email protected][email protected]{@eZqBoSuAqZsBsE[sCMeCEaB?{[email protected]}[email protected]{[email protected]~AmH`BgKh[email protected]{M`C}[email protected]}ABgAL_AX}@[email protected]{@[email protected]@[email protected]@[email protected]@tAGXQfACTEfBDvBJrEAxCG`CInBBHDFMhBUrDkAlQkAhQSjDQlFIrLJx^HzLBbPChBGbCQdCMlB[[email protected]@[email protected]@[email protected][email protected]`JaBlH[[email protected]`[email protected]@|EiAzH_DxS]rAeD|[email protected]@[email protected]`[email protected]@[email protected]`[email protected]@fBVhCVpCNdCLtCD|[email protected]?`[email protected][email protected]@[email protected]@[email protected]{AImBQgBW[[email protected]"},
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: {},
},
}
あなたのためにコードを書くようにお願いしているようです。あなたが望むJSONと一致する構造体を作成します。そしてGoの 'map'に' Decode'します。たくさんの例がオンラインです。例えば。 https://gobyexample.com/json – eduncan911
これが役に立ちます。ありがとう –