-
Notifications
You must be signed in to change notification settings - Fork 0
/
nearest.go
30 lines (22 loc) · 796 Bytes
/
nearest.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
package gosrm
import (
"context"
)
// nearestServiceURL is the base path of OSRM nearest service.
const nearestServiceURL string = "/nearest/v1"
// NearestResponse is the response of OSRM's nearest service.
type NearestResponse struct {
Response
// Waypoints is an array of waypoint objects sorted by distance to the input coordinate.
Waypoints []NearestWaypoint `json:"waypoints"`
}
// Nearest snaps a coordinate to the street network and returns the nearest n matches.
func Nearest(ctx context.Context, osrm OSRMClient, req Request, opts ...Option) (*NearestResponse, error) {
u := req.buildURLPath(*osrm.baseURL, nearestServiceURL)
osrm.applyOpts(u, opts)
var res NearestResponse
if err := osrm.get(ctx, u.String(), &res); err != nil {
return nil, err
}
return &res, nil
}