diff --git a/docs/http.md b/docs/http.md index 17f1a41fe93..16d1ed0ef7a 100644 --- a/docs/http.md +++ b/docs/http.md @@ -283,6 +283,12 @@ In addition to the [general options](#general-options) the following options are |timestamp |`integer` UNIX-like timestamp | |radius |`double >= 0` (default 5m) | +The radius for each point should be the standard error of the location, measured in meters from the true location. Use +`Location.getAccuracy()` on Android or `CLLocation.horizontalAccuracy` on iOS. This value is used to determine which +points should be considered as candidates (larger radius means more candidates) and how likely each candidate is (larger +radius means far-away candidates are penalized less). The area to search is chosen such that the correct candidate +should be considered 99.9% of the time (for more details, see https://github.com/Project-OSRM/osrm-backend/pull/3184). + ### Response - `code` if the request was successful `Ok` otherwise see the service dependent and general status codes. - `tracepoints`: Array of `Waypoint` objects representing all points of the trace in order. diff --git a/src/engine/plugins/match.cpp b/src/engine/plugins/match.cpp index 4fa6a97fe12..67a1f2c9027 100644 --- a/src/engine/plugins/match.cpp +++ b/src/engine/plugins/match.cpp @@ -19,6 +19,13 @@ #include #include +static double search_radius_for_gps_radius(double gps_radius) { + // For a given GPS radius, determine the radius we need to search for candidate street segments + // to have a 99.9% chance of finding the correct segment. + // For more detail, see the analysis at https://github.com/Project-OSRM/osrm-backend/pull/3184 + return std::min(gps_radius * 3.5 + 45, 200.0); +} + namespace osrm { namespace engine @@ -152,16 +159,9 @@ Status MatchPlugin::HandleRequest(const std::shared_ptr &maybe_radius) { - if (maybe_radius) - { - return *maybe_radius * RADIUS_MULTIPLIER; - } - else - { - return DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER; - } - + [&](const boost::optional &maybe_radius) { + double gps_radius = maybe_radius ? *maybe_radius : DEFAULT_GPS_PRECISION; + return search_radius_for_gps_radius(gps_radius); }); }