forked from vladoatanasov/valhalla-go-bindings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocate.go
174 lines (168 loc) · 5.94 KB
/
locate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package valhalla
import (
"bytes"
"encoding/json"
)
type LocateResponse []struct {
InputLon float64 `json:"input_lon"`
InputLat float64 `json:"input_lat"`
Nodes []struct {
TrafficSignal bool `json:"traffic_signal"`
Type string `json:"type"`
Lat float64 `json:"lat"`
NodeID struct {
ID int `json:"id"`
Value int64 `json:"value"`
TileID int `json:"tile_id"`
Level int `json:"level"`
} `json:"node_id"`
Access struct {
Wheelchair bool `json:"wheelchair"`
Taxi bool `json:"taxi"`
HOV bool `json:"HOV"`
Truck bool `json:"truck"`
Emergency bool `json:"emergency"`
Pedestrian bool `json:"pedestrian"`
Car bool `json:"car"`
Bus bool `json:"bus"`
Bicycle bool `json:"bicycle"`
} `json:"access"`
Lon float64 `json:"lon"`
EdgeCount int `json:"edge_count"`
Administrative struct {
TimeZonePosix string `json:"time_zone_posix"`
StandardTimeZoneName string `json:"standard_time_zone_name"`
Iso31661 string `json:"iso_3166-1"`
DaylightSavingsTimeZoneName string `json:"daylight_savings_time_zone_name"`
Country string `json:"country"`
Iso31662 string `json:"iso_3166-2"`
State string `json:"state"`
} `json:"administrative"`
IntersectionType string `json:"intersection_type"`
Density int `json:"density"`
LocalEdgeCount int `json:"local_edge_count"`
ModeChange bool `json:"mode_change"`
} `json:"nodes"`
Edges []struct {
EdgeID struct {
ID int `json:"id"`
Value int64 `json:"value"`
TileID int `json:"tile_id"`
Level int `json:"level"`
} `json:"edge_id"`
EdgeInfo struct {
Names []string `json:"names"`
Shape string `json:"shape"`
WayID int `json:"way_id"`
} `json:"edge_info"`
Edge struct {
Classification struct {
Link bool `json:"link"`
Internal bool `json:"internal"`
Surface string `json:"surface"`
Classification string `json:"classification"`
} `json:"classification"`
GeoAttributes struct {
Curvature int `json:"curvature"`
WeightedGrade float32 `json:"weighted_grade"`
Length int `json:"length"`
} `json:"geo_attributes"`
SpeedType string `json:"speed_type"`
BikeNetwork struct {
Mountain bool `json:"mountain"`
Local bool `json:"local"`
Regional bool `json:"regional"`
National bool `json:"national"`
} `json:"bike_network"`
CycleLane string `json:"cycle_lane"`
TrafficSignal bool `json:"traffic_signal"`
Unreachable bool `json:"unreachable"`
RoundAbout bool `json:"round_about"`
Access struct {
Truck bool `json:"truck"`
Pedestrian bool `json:"pedestrian"`
Wheelchair bool `json:"wheelchair"`
Taxi bool `json:"taxi"`
HOV bool `json:"HOV"`
Emergency bool `json:"emergency"`
Motorcycle bool `json:"motorcycle"`
Car bool `json:"car"`
Moped bool `json:"moped"`
Bus bool `json:"bus"`
Bicycle bool `json:"bicycle"`
} `json:"access"`
DestinationOnly bool `json:"destination_only"`
CountryCrossing bool `json:"country_crossing"`
Forward bool `json:"forward"`
Seasonal bool `json:"seasonal"`
Use string `json:"use"`
DriveOnRight bool `json:"drive_on_right"`
LaneCount int `json:"lane_count"`
TruckRoute bool `json:"truck_route"`
PartOfComplexRestriction bool `json:"part_of_complex_restriction"`
StartRestriction struct {
Truck bool `json:"truck"`
Pedestrian bool `json:"pedestrian"`
Wheelchair bool `json:"wheelchair"`
Taxi bool `json:"taxi"`
HOV bool `json:"HOV"`
Emergency bool `json:"emergency"`
Motorcycle bool `json:"motorcycle"`
Car bool `json:"car"`
Moped bool `json:"moped"`
Bus bool `json:"bus"`
Bicycle bool `json:"bicycle"`
} `json:"start_restriction"`
Toll bool `json:"toll"`
HasExitSign bool `json:"has_exit_sign"`
AccessRestriction bool `json:"access_restriction"`
Bridge bool `json:"bridge"`
Tunnel bool `json:"tunnel"`
SpeedLimit int `json:"speed_limit"`
NotThru bool `json:"not_thru"`
EndRestriction struct {
Truck bool `json:"truck"`
Pedestrian bool `json:"pedestrian"`
Wheelchair bool `json:"wheelchair"`
Taxi bool `json:"taxi"`
HOV bool `json:"HOV"`
Emergency bool `json:"emergency"`
Motorcycle bool `json:"motorcycle"`
Car bool `json:"car"`
Moped bool `json:"moped"`
Bus bool `json:"bus"`
Bicycle bool `json:"bicycle"`
} `json:"end_restriction"`
Speed int `json:"speed"`
EndNode struct {
ID int `json:"id"`
Value int64 `json:"value"`
TileID int `json:"tile_id"`
Level int `json:"level"`
} `json:"end_node"`
} `json:"edge"`
MinimumReachability int `json:"minimum_reachability"`
TrafficSegments []interface{} `json:"traffic_segments"`
Distance float64 `json:"distance"`
PercentAlong float64 `json:"percent_along"`
CorrelatedLon float64 `json:"correlated_lon"`
SideOfStreet string `json:"side_of_street"`
CorrelatedLat float64 `json:"correlated_lat"`
} `json:"edges"`
}
func (c *Client) Locate(request RouteRequest) (LocateResponse, error) {
r, err := json.Marshal(request)
if err != nil {
return LocateResponse{}, err
}
response, err := c.request("GET", "locate", bytes.NewReader(r))
if err != nil {
return LocateResponse{}, err
}
result := LocateResponse{}
err = json.Unmarshal(response, &result)
if err != nil {
return LocateResponse{}, err
}
return result, nil
}