1
1
### GOSRM
2
2
---
3
- ** GOSRM** is an OSRM client written in Go. It implements all OSRM 5.x installations.
3
+ ** GOSRM** is an OSRM client written in Go. It implements all OSRM 5.x installations.
4
4
If you want to get the most out of this package I highly recommend to read OSRM [ docs] ( https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md ) .
5
5
6
6
#### Features
@@ -16,80 +16,80 @@ If you want to get the most out of this package I highly recommend to read OSRM
16
16
---
17
17
Requires Go >= 1.18: ` go get github.com/mojixcoder/gosrm `
18
18
19
- #### How to use
19
+ #### How To Use
20
20
---
21
21
``` go
22
22
package main
23
23
24
24
import (
25
- " context"
26
- " fmt"
25
+ " context"
26
+ " fmt"
27
27
28
- " github.com/mojixcoder/gosrm"
28
+ " github.com/mojixcoder/gosrm"
29
29
)
30
30
31
31
func main () {
32
- osrm , err := gosrm.New (" http://router.project-osrm.org" )
33
- checkErr (err)
34
-
35
- nearestRes , err := gosrm.Nearest (context.Background (), osrm, gosrm.Request {
36
- Profile: gosrm.ProfileDriving ,
37
- Coordinates: []gosrm.Coordinate {{13.388860 , 52.517037 }},
38
- }, gosrm.WithNumber (3 ), gosrm.WithBearings ([]gosrm.Bearing {{Value: 0 , Range: 20 }}))
39
- checkErr (err)
40
-
41
- fmt.Println (" ### Nearest Response ###" )
42
- fmt.Printf (" %#v \n " , nearestRes)
43
- fmt.Println (" ##########" )
44
-
45
- // String type represents the type of geometries returned by OSRM.
46
- // It can be either string or gosrm.LineString based on geometries option.
47
- // If you don't specify any geometries the default is polyline and you can use string.
48
- routeRes , err := gosrm.Route [string ](context.Background (), osrm, gosrm.Request {
49
- Profile: gosrm.ProfileDriving ,
50
- Coordinates: []gosrm.Coordinate {{13.388860 , 52.517037 }, {13.397634 , 52.529407 }, {13.428555 , 52.523219 }},
51
- })
52
- checkErr (err)
53
-
54
- fmt.Println (" \n ### Route Response ###" )
55
- fmt.Printf (" %#v \n " , routeRes)
56
- fmt.Println (" ##########" )
57
-
58
- tableRes , err := gosrm.Table (context.Background (), osrm, gosrm.Request {
59
- Profile: gosrm.ProfileDriving ,
60
- Coordinates: []gosrm.Coordinate {{13.388860 , 52.517037 }, {13.397634 , 52.529407 }, {13.428555 , 52.523219 }},
61
- }, gosrm.WithSources ([]uint16 {0 , 1 }), gosrm.WithDestinations ([]uint16 {2 }))
62
- checkErr (err)
63
-
64
- fmt.Println (" \n ### Table Response ###" )
65
- fmt.Printf (" %#v \n " , tableRes)
66
- fmt.Println (" ##########" )
67
-
68
- // This time we use geojson geometries so geometry type is gosrm.LineString not string.
69
- matchRes , err := gosrm.Match [gosrm.LineString ](context.Background (), osrm, gosrm.Request {
70
- Profile: gosrm.ProfileDriving ,
71
- Coordinates: []gosrm.Coordinate {{13.3122 , 52.5322 }, {13.3065 , 52.5283 }},
72
- }, gosrm.WithAnnotations (gosrm.AnnotationsTrue ), gosrm.WithGeometries (gosrm.GeometryGeoJSON ))
73
- checkErr (err)
74
-
75
- fmt.Println (" \n ### Match Response ###" )
76
- fmt.Printf (" %#v \n " , matchRes)
77
- fmt.Println (" ##########" )
78
-
79
- tripRes , err := gosrm.Trip [string ](context.Background (), osrm, gosrm.Request {
80
- Profile: gosrm.ProfileDriving ,
81
- Coordinates: []gosrm.Coordinate {{13.388860 , 52.517037 }, {13.397634 , 52.529407 }, {13.428555 , 52.523219 }, {13.418555 , 52.523215 }},
82
- }, gosrm.WithSource (gosrm.SourceFirst ), gosrm.WithDestination (gosrm.DestinationLast ))
83
- checkErr (err)
84
-
85
- fmt.Println (" \n ### Trip Response ###" )
86
- fmt.Printf (" %#v \n " , tripRes)
87
- fmt.Println (" ##########" )
32
+ osrm , err := gosrm.New (" http://router.project-osrm.org" )
33
+ checkErr (err)
34
+
35
+ nearestRes , err := gosrm.Nearest (context.Background (), osrm, gosrm.Request {
36
+ Profile: gosrm.ProfileDriving ,
37
+ Coordinates: []gosrm.Coordinate {{13.388860 , 52.517037 }},
38
+ }, gosrm.WithNumber (3 ), gosrm.WithBearings ([]gosrm.Bearing {{Value: 0 , Range: 20 }}))
39
+ checkErr (err)
40
+
41
+ fmt.Println (" ### Nearest Response ###" )
42
+ fmt.Printf (" %#v \n " , nearestRes)
43
+ fmt.Println (" ##########" )
44
+
45
+ // String type represents the type of geometries returned by OSRM.
46
+ // It can be either string or gosrm.LineString based on geometries option.
47
+ // If you don't specify any geometries the default is polyline and you can use string.
48
+ routeRes , err := gosrm.Route [string ](context.Background (), osrm, gosrm.Request {
49
+ Profile: gosrm.ProfileDriving ,
50
+ Coordinates: []gosrm.Coordinate {{13.388860 , 52.517037 }, {13.397634 , 52.529407 }, {13.428555 , 52.523219 }},
51
+ })
52
+ checkErr (err)
53
+
54
+ fmt.Println (" \n ### Route Response ###" )
55
+ fmt.Printf (" %#v \n " , routeRes)
56
+ fmt.Println (" ##########" )
57
+
58
+ tableRes , err := gosrm.Table (context.Background (), osrm, gosrm.Request {
59
+ Profile: gosrm.ProfileDriving ,
60
+ Coordinates: []gosrm.Coordinate {{13.388860 , 52.517037 }, {13.397634 , 52.529407 }, {13.428555 , 52.523219 }},
61
+ }, gosrm.WithSources ([]uint16 {0 , 1 }), gosrm.WithDestinations ([]uint16 {2 }))
62
+ checkErr (err)
63
+
64
+ fmt.Println (" \n ### Table Response ###" )
65
+ fmt.Printf (" %#v \n " , tableRes)
66
+ fmt.Println (" ##########" )
67
+
68
+ // This time we use geojson geometries so geometry type is gosrm.LineString not string.
69
+ matchRes , err := gosrm.Match [gosrm.LineString ](context.Background (), osrm, gosrm.Request {
70
+ Profile: gosrm.ProfileDriving ,
71
+ Coordinates: []gosrm.Coordinate {{13.3122 , 52.5322 }, {13.3065 , 52.5283 }},
72
+ }, gosrm.WithAnnotations (gosrm.AnnotationsTrue ), gosrm.WithGeometries (gosrm.GeometryGeoJSON ))
73
+ checkErr (err)
74
+
75
+ fmt.Println (" \n ### Match Response ###" )
76
+ fmt.Printf (" %#v \n " , matchRes)
77
+ fmt.Println (" ##########" )
78
+
79
+ tripRes , err := gosrm.Trip [string ](context.Background (), osrm, gosrm.Request {
80
+ Profile: gosrm.ProfileDriving ,
81
+ Coordinates: []gosrm.Coordinate {{13.388860 , 52.517037 }, {13.397634 , 52.529407 }, {13.428555 , 52.523219 }, {13.418555 , 52.523215 }},
82
+ }, gosrm.WithSource (gosrm.SourceFirst ), gosrm.WithDestination (gosrm.DestinationLast ))
83
+ checkErr (err)
84
+
85
+ fmt.Println (" \n ### Trip Response ###" )
86
+ fmt.Printf (" %#v \n " , tripRes)
87
+ fmt.Println (" ##########" )
88
88
}
89
89
90
90
func checkErr (err error ) {
91
- if err != nil {
92
- panic (err)
93
- }
91
+ if err != nil {
92
+ panic (err)
93
+ }
94
94
}
95
- ```
95
+ ```
0 commit comments