![]() |
VOOZH | about |
dotnet add package Osrm.HttpApiClient --version 1.14.0
NuGet\Install-Package Osrm.HttpApiClient -Version 1.14.0
<PackageReference Include="Osrm.HttpApiClient" Version="1.14.0" />
<PackageVersion Include="Osrm.HttpApiClient" Version="1.14.0" />Directory.Packages.props
<PackageReference Include="Osrm.HttpApiClient" />Project file
paket add Osrm.HttpApiClient --version 1.14.0
#r "nuget: Osrm.HttpApiClient, 1.14.0"
#:package Osrm.HttpApiClient@1.14.0
#addin nuget:?package=Osrm.HttpApiClient&version=1.14.0Install as a Cake Addin
#tool nuget:?package=Osrm.HttpApiClient&version=1.14.0Install as a Cake Tool
Http API Client for OSRM library. Supports FlatBuffers format as well.
$ dotnet add package Osrm.HttpApiClient / PM> Install-Package Osrm.HttpApiClient
Nothing much to add, this is simple HTTP client for OSRM, let's proceed to these clean and fluent examples:
public static RouteRequest<GeoJsonGeometry> Full_GeoJson_route_query
=> OsrmServices
.GeoJsonRoute(
Driving,
GeographicalCoordinates.Create(
Coordinate.Create(13.388860, 52.517037),
Coordinate.Create(13.397634, 52.529407),
Coordinate.Create(13.428555, 52.523219)))
.Overview(Overview.Full)
.ReturnAlternatives()
.ReturnAnnotations()
.ReturnSteps()
.Build();
public static RouteRequest<PolylineGeometry> Full_Polyline_route_query
=> OsrmServices
.PolylineRoute(
Driving,
GeographicalCoordinates.Create(
Coordinate.Create(13.388860, 52.517037),
Coordinate.Create(13.397634, 52.529407),
Coordinate.Create(13.428555, 52.523219)))
.Overview(Overview.Full)
.ReturnAlternatives()
.ReturnAnnotations()
.ReturnSteps()
.Build();
public static RouteRequest<GeoJsonGeometry> Query_on_Berlin_with_three_coordinates
=> OsrmServices
.GeoJsonRoute(
Driving,
GeographicalCoordinates.Create(
Coordinate.Create(13.388860, 52.517037),
Coordinate.Create(13.397634, 52.529407),
Coordinate.Create(13.428555, 52.523219)))
.Overview(Overview.False)
.Build();
public static RouteRequest<GeoJsonGeometry> Query_on_Berlin_excluding_the_usage_of_motorways
=> OsrmServices
.GeoJsonRoute(
Driving,
GeographicalCoordinates.Create(
Coordinate.Create(13.388860, 52.517037),
Coordinate.Create(13.397634, 52.529407)))
.Exclude(ClassName.From("motorway"))
.Build();
public static RouteRequest<GeoJsonGeometry> Query_on_Berlin_using_polyline
=> OsrmServices
.GeoJsonRoute(
Driving,
PolylineCoordinates.Create("ofp_Ik_vpAilAyu@te@g`E"))
.Overview(Overview.False)
.Build();
public static NearestRequest Querying_nearest_three_snapped_locations
=> OsrmServices
.Nearest(
Driving,
Coordinate.Create(13.388860, 52.517037, Bearing.Create(0, 20)))
.NearestSegments(3)
.Build();
public static TableRequest A_3x3_matrix
=> OsrmServices
.Table(
Driving,
GeographicalCoordinates.Create(
Coordinate.Create(13.388860, 52.517037),
Coordinate.Create(13.397634, 52.529407),
Coordinate.Create(13.428555, 52.523219)))
.Build();
public static TableRequest An_asymmetric_3x2_duration_matrix_with_from_the_polyline_encoded_locations
=> OsrmServices
.Table(
Driving,
PolylineCoordinates.Create("egs_Iq_aqAppHzbHulFzeMe`EuvKpnCglA"))
.Sources(0, 1, 3)
.Destinations(2, 4)
.Build();
public static TableRequest A_3x3_duration_matrix_and_a_3x3_distance_matrix_for_CH
=> OsrmServices
.Table(
Driving,
GeographicalCoordinates.Create(
Coordinate.Create(13.388860, 52.517037),
Coordinate.Create(13.397634, 52.529407),
Coordinate.Create(13.428555, 52.523219)))
.Annotations(Annotations.DurationAndDistance)
.Build();
public static TripRequest<GeoJsonGeometry> Round_trip_in_Berlin_with_four_stops_starting_at_the_first_stop_ending_at_the_last
=> OsrmServices
.GeoJsonTrip(
Driving,
GeographicalCoordinates.Create(
Coordinate.Create(13.388860, 52.517037),
Coordinate.Create(13.397634, 52.529407),
Coordinate.Create(13.428555, 52.523219),
Coordinate.Create(13.418555, 52.523215)))
.WithRoundTrip(
SourceCoordinate.First,
DestinationCoordinate.Last)
.Build();
public static TileRequest Z_13_tile_for_downtown_San_Francisco
=> OsrmServices
.Tile(
Driving,
x: 1310,
y: 3166,
zoom: 13);
Check full examples inside Osrm.Examples project. Also, check Osrm.ConsoleExamples.
So, the best way to start building your request, is to use handy static methods from OsrmServices class. Anyway, you can use plain models, if you want, it's up to you.
Currently supported services are:
Feel free to open PR's, in case something warns you or you found anything buggy here!
Simply register OsrmHttpApiClient in DI container:
services.AddHttpClient<OsrmHttpApiClient>(httpClient =>
{
httpClient.BaseAddress = new Uri("http://router.project-osrm.org");
});
System.Text.Json, which is built into net5.0. Simple, fast, unobtrusive.
Polyline and Polyline6 geometry types are supported by corresponding JSON serializers.
Check OsrmHttpApiClient.DefaultJsonSerializerOptions field for used options.
FlatSharp is used to parse.fbs response. This is the only one external dependency.
Sure!
In case you want to change JSON serializer options - set them new to the JsonSerializerOptions property inside OsrmHttpApiClient.
In case you want to change any model, they are all unsealed, feel free to inherit them and change whatever you want. This library was designed in mind to always keep valid state inside models, so when modifying models, it's your responsibility to keep that valid state limitations.
You can find useful information here: Slippy map tilenames.
SlippyMapTiles methods are also provided, to help with conversion between lon/lat and X/Y.
You should pass FlatBuffersFormat to your builder. Furthermore, special OsrmFlatBuffersHttpApiClient and OsrmFlatBuffersStaticHttpApiClient are used to process flatbuffers format.
Creation of the specified query objects is measured.
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
AMD Ryzen 5 2600, 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.202
[Host] : .NET Core 5.0.5 (CoreCLR 5.0.521.16609, CoreFX 5.0.521.16609), X64 RyuJIT
DefaultJob : .NET Core 5.0.5 (CoreCLR 5.0.521.16609, CoreFX 5.0.521.16609), X64 RyuJIT
| Method | Mean | Error | StdDev | Median | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---|---|---|---|---|---|---|---|---|
| Full_GeoJson_route_query | 83.30 ns | 1.644 ns | 2.922 ns | 82.77 ns | 0.0975 | - | - | 408 B |
| Full_Polyline_route_query | 87.41 ns | 1.705 ns | 2.094 ns | 86.57 ns | 0.0975 | - | - | 408 B |
| Query_on_Berlin_with_three_coordinates | 80.44 ns | 1.074 ns | 0.897 ns | 80.30 ns | 0.0975 | - | - | 408 B |
| Query_on_Berlin_excluding_the_usage_of_motorways | 92.39 ns | 1.904 ns | 3.847 ns | 91.12 ns | 0.0918 | - | - | 384 B |
| Query_on_Berlin_using_polyline | 55.30 ns | 1.152 ns | 2.048 ns | 54.91 ns | 0.0343 | - | - | 144 B |
| Querying_nearest_three_snapped_locations | 61.50 ns | 1.303 ns | 1.694 ns | 61.07 ns | 0.0612 | - | - | 256 B |
| A_3x3_matrix | 84.98 ns | 1.751 ns | 2.084 ns | 84.10 ns | 0.1070 | - | - | 448 B |
| A_1x3_duration_matrix | 97.34 ns | 2.005 ns | 4.994 ns | 97.00 ns | 0.1147 | - | - | 480 B |
| An_asymmetric_3x2_duration_matrix_with_from_the_polyline_encoded_locations | 68.64 ns | 1.428 ns | 1.700 ns | 69.32 ns | 0.0612 | - | - | 256 B |
| A_3x3_duration_matrix | 91.09 ns | 1.895 ns | 4.354 ns | 90.03 ns | 0.1070 | - | - | 448 B |
| A_3x3_duration_matrix_for_CH | 93.48 ns | 1.944 ns | 4.659 ns | 92.36 ns | 0.1070 | - | - | 448 B |
| A_3x3_duration_matrix_and_a_3x3_distance_matrix_for_CH | 94.02 ns | 1.607 ns | 1.850 ns | 94.12 ns | 0.1070 | - | - | 448 B |
| Round_trip_in_Berlin_with_three_stops | 86.12 ns | 2.575 ns | 7.471 ns | 84.09 ns | 0.0975 | - | - | 408 B |
| Round_trip_in_Berlin_with_four_stops_starting_at_the_first_stop_ending_at_the_last | 104.02 ns | 2.963 ns | 8.455 ns | 101.19 ns | 0.1166 | - | - | 488 B |
| Z_13_tile_for_downtown_San_Francisco | 11.35 ns | 0.293 ns | 0.536 ns | 11.15 ns | 0.0095 | - | - | 40 B |
This library is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 is compatible. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.14.0 | 3,412 | 5/9/2025 |
| 1.13.0 | 138,844 | 3/23/2023 |
| 1.12.0 | 547 | 2/8/2023 |
| 1.11.0 | 4,157 | 8/15/2022 |
| 1.10.0 | 593 | 8/15/2022 |
| 1.9.0 | 564 | 8/15/2022 |
| 1.8.0 | 589 | 8/14/2022 |
| 1.7.0 | 6,991 | 10/7/2021 |
| 1.6.0 | 514 | 10/5/2021 |
| 1.5.0 | 523 | 10/5/2021 |
| 1.4.0 | 522 | 10/5/2021 |
| 1.3.0 | 526 | 10/4/2021 |
| 1.2.0 | 606 | 8/23/2021 |
| 1.1.0 | 542 | 5/13/2021 |
| 1.0.0 | 553 | 2/7/2021 |