Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added walking options #991

Merged
merged 12 commits into from
May 10, 2019
31 changes: 31 additions & 0 deletions samples/src/main/java/com/mapbox/samples/BasicDirections.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mapbox.api.directions.v5.DirectionsCriteria;
import com.mapbox.api.directions.v5.MapboxDirections;
import com.mapbox.api.directions.v5.WalkingOptions;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.geojson.Point;
import com.mapbox.sample.BuildConfig;
Expand All @@ -19,6 +20,7 @@ public class BasicDirections {

public static void main(String[] args) throws IOException {
simpleMapboxDirectionsRequest();
simpleMapboxDirectionsWalkingRequest();
asyncMapboxDirectionsRequest();
simpleMapboxDirectionsPostRequest();
}
Expand Down Expand Up @@ -46,6 +48,35 @@ private static void simpleMapboxDirectionsRequest() throws IOException {
response.body().routes().get(0).distance());
}

/**
* Demonstrates how to make the most basic GET directions request using the walking profile.
*
* @throws IOException signals that an I/O exception of some sort has occurred
*/
private static void simpleMapboxDirectionsWalkingRequest() throws IOException {

MapboxDirections.Builder builder = MapboxDirections.builder();

builder.accessToken(BuildConfig.MAPBOX_ACCESS_TOKEN);
builder.origin(Point.fromLngLat(-95.6332, 29.7890));
builder.destination(Point.fromLngLat(-95.3591, 29.7576));
builder.profile("walking");
builder.walkingOptions(
WalkingOptions.builder()
.walkingSpeed(1.0)
.walkwayBias(0.6)
.alleyBias(0.7)
.build());

// 2. That's it! Now execute the command and get the response.
Response<DirectionsResponse> response = builder.build().executeCall();

// 3. Log information from the response
System.out.printf("Check that the GET response is successful %b", response.isSuccessful());
System.out.printf("%nGet the first routes distance from origin to destination: %f",
response.body().routes().get(0).distance());
}

/**
* Demonstrates how to make the most basic POST directions request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private List<DirectionsRoute> generateRouteOptions(Response<DirectionsResponse>
.accessToken(mapboxDirections.accessToken())
.requestUuid(response.body().uuid())
.baseUrl(mapboxDirections.baseUrl())
.walkingOptions(mapboxDirections.walkingOptions())
.build()
).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,43 @@ public interface DirectionsService {
* Constructs the html get call using the information passed in through the
* {@link MapboxDirections.Builder}.
*
* @param userAgent the user agent
* @param user the user
* @param profile the profile directions should use
* @param coordinates the coordinates the route should follow
* @param accessToken Mapbox access token
* @param alternatives define whether you want to receive more then one route
* @param geometries route geometry
* @param overview route full, simplified, etc.
* @param radiuses start at the most efficient point within the radius
* @param steps define if you'd like the route steps
* @param bearings used to filter the road segment the waypoint will be placed on by
* direction and dictates the angle of approach
* @param continueStraight define whether the route should continue straight even if the
* route will be slower
* @param annotations an annotations object that contains additional details about each
* line segment along the route geometry. Each entry in an
* annotations field corresponds to a coordinate along the route
* geometry
* @param language language of returned turn-by-turn text instructions
* @param roundaboutExits Add extra step when roundabouts occur with additional information
* for the user
* @param voiceInstructions request that the response contain voice instruction information,
* useful for navigation
* @param bannerInstructions request that the response contain banner instruction information,
* useful for navigation
* @param voiceUnits voice units
* @param exclude exclude tolls, motorways or more along your route
* @param approaches which side of the road to approach a waypoint
* @param waypointIndices which input coordinates should be treated as waypoints/separate legs.
* Note: coordinate indices not added here act as silent waypoints
* @param waypointNames custom names for waypoints used for the arrival instruction
* @param waypointTargets list of coordinate pairs for drop-off locations
* @param enableRefresh whether the routes should be refreshable
* @param userAgent the user agent
* @param user the user
* @param profile the profile directions should use
* @param coordinates the coordinates the route should follow
* @param accessToken Mapbox access token
* @param alternatives define whether you want to receive more then one route
* @param geometries route geometry
* @param overview route full, simplified, etc.
* @param radiuses start at the most efficient point within the radius
* @param steps define if you'd like the route steps
* @param bearings used to filter the road segment the waypoint will be placed on by
* direction and dictates the angle of approach
* @param continueStraight define whether the route should continue straight even if the
* route will be slower
* @param annotations an annotations object that contains additional details about each
* line segment along the route geometry. Each entry in an
* annotations field corresponds to a coordinate along the route
* geometry
* @param language language of returned turn-by-turn text instructions
* @param roundaboutExits Add extra step when roundabouts occur with additional information
* for the user
* @param voiceInstructions request that the response contain voice instruction information,
* useful for navigation
* @param bannerInstructions request that the response contain banner instruction information,
* useful for navigation
* @param voiceUnits voice units
* @param exclude exclude tolls, motorways or more along your route
* @param approaches which side of the road to approach a waypoint
* @param waypointIndices which input coordinates should be treated as waypoints/separate legs
* Note: coordinate indices not added here act as silent waypoints
* @param waypointNames custom names for waypoints used for the arrival instruction
* @param waypointTargets list of coordinate pairs for drop-off locations
* @param enableRefresh whether the routes should be refreshable
* @param walkingSpeed walking speed
* @param walkwayBias a factor that modifies the cost when encountering roads or paths
* that do not allow vehicles and are set aside for pedestrian use
* @param alleyBias a factor that modifies the cost when alleys are encountered
* @return the {@link DirectionsResponse} in a Call wrapper
* @since 1.0.0
*/
Expand Down Expand Up @@ -83,46 +87,49 @@ Call<DirectionsResponse> getCall(
@Query("waypoints") String waypointIndices,
@Query("waypoint_names") String waypointNames,
@Query("waypoint_targets") String waypointTargets,
@Query("enable_refresh") Boolean enableRefresh
@Query("enable_refresh") Boolean enableRefresh,
@Query("walking_speed") Double walkingSpeed,
@Query("walkway_bias") Double walkwayBias,
@Query("alley_bias") Double alleyBias
);

/**
* Constructs the post html call using the information passed in through the
* {@link MapboxDirections.Builder}.
*
* @param userAgent the user agent
* @param user the user
* @param profile the profile directions should use
* @param coordinates the coordinates the route should follow
* @param accessToken Mapbox access token
* @param alternatives define whether you want to receive more then one route
* @param geometries route geometry
* @param overview route full, simplified, etc.
* @param radiuses start at the most efficient point within the radius
* @param steps define if you'd like the route steps
* @param bearings used to filter the road segment the waypoint will be placed on by
* direction and dictates the angle of approach
* @param continueStraight define whether the route should continue straight even if the
* route will be slower
* @param annotations an annotations object that contains additional details about each
* line segment along the route geometry. Each entry in an
* annotations field corresponds to a coordinate along the route
* geometry
* @param language language of returned turn-by-turn text instructions
* @param roundaboutExits Add extra step when roundabouts occur with additional information
* for the user
* @param voiceInstructions request that the response contain voice instruction information,
* useful for navigation
* @param bannerInstructions request that the response contain banner instruction information,
* useful for navigation
* @param voiceUnits voice units
* @param exclude exclude tolls, motorways or more along your route
* @param approaches which side of the road to approach a waypoint
* @param waypointIndices which input coordinates should be treated as waypoints/separate legs.
* Note: coordinate indices not added here act as silent waypoints
* @param waypointNames custom names for waypoints used for the arrival instruction
* @param waypointTargets list of coordinate pairs for drop-off locations
* @param enableRefresh whether the routes should be refreshable
* @param userAgent the user agent
* @param user the user
* @param profile the profile directions should use
* @param coordinates the coordinates the route should follow
* @param accessToken Mapbox access token
* @param alternatives define whether you want to receive more then one route
* @param geometries route geometry
* @param overview route full, simplified, etc.
* @param radiuses start at the most efficient point within the radius
* @param steps define if you'd like the route steps
* @param bearings used to filter the road segment the waypoint will be placed on by
* direction and dictates the angle of approach
* @param continueStraight define whether the route should continue straight even if the
* route will be slower
* @param annotations an annotations object that contains additional details about each
* line segment along the route geometry. Each entry in an
* annotations field corresponds to a coordinate along the route
* geometry
* @param language language of returned turn-by-turn text instructions
* @param roundaboutExits Add extra step when roundabouts occur with additional information
* for the user
* @param voiceInstructions request that the response contain voice instruction information,
* useful for navigation
* @param bannerInstructions request that the response contain banner instruction information,
* useful for navigation
* @param voiceUnits voice units
* @param exclude exclude tolls, motorways or more along your route
* @param approaches which side of the road to approach a waypoint
* @param waypointIndices which input coordinates should be treated as waypoints/separate legs
* Note: coordinate indices not added here act as silent waypoints
* @param waypointNames custom names for waypoints used for the arrival instruction
* @param waypointTargets list of coordinate pairs for drop-off locations
* @param enableRefresh whether the routes should be refreshable
* @return the {@link DirectionsResponse} in a Call wrapper
* @since 4.6.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ private Call<DirectionsResponse> get() {
waypointIndices(),
waypointNames(),
waypointTargets(),
enableRefresh());
enableRefresh(),
walkingSpeed(),
walkwayBias(),
alleyBias()
);
}

private Call<DirectionsResponse> post() {
// todo add walking options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we revert these changes back? It seems walking supports POST too now.

return getService().postCall(
ApiCallHelper.getHeaderUserAgent(clientAppName()),
user(),
Expand All @@ -135,7 +140,8 @@ private Call<DirectionsResponse> post() {
waypointIndices(),
waypointNames(),
waypointTargets(),
enableRefresh());
enableRefresh()
);
}

@Override
Expand Down Expand Up @@ -327,6 +333,40 @@ private static String formatWaypointTargets(Point[] waypointTargets) {
@Nullable
abstract Boolean usePostMethod();

@Nullable
abstract WalkingOptions walkingOptions();

@Nullable
Double walkingSpeed() {
if (hasWalkingOptions()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment: Guard clauses normally represent the unexpected behavior i.e.

if (!hasWalkingOptions()) {
  return null;
}
return walkingOptions().walkingSpeed();

return walkingOptions().walkingSpeed();
}

return null;
}

@Nullable
Double walkwayBias() {
if (hasWalkingOptions()) {
return walkingOptions().walkwayBias();
}

return null;
}

@Nullable
Double alleyBias() {
if (hasWalkingOptions()) {
return walkingOptions().alleyBias();
}

return null;
}

private boolean hasWalkingOptions() {
return walkingOptions() != null;
}

/**
* Build a new {@link MapboxDirections} object with the initial values set for
* {@link #baseUrl()}, {@link #profile()}, {@link #user()}, and {@link #geometries()}.
Expand Down Expand Up @@ -830,6 +870,17 @@ public Builder get() {
return this;
}

/**
* To be used to specify settings for use with the walking profile.
*
* @param walkingOptions options to use for walking profile
* @return this builder for chaining options together
* @since 4.8.0
*/
public abstract Builder walkingOptions(@NonNull WalkingOptions walkingOptions);

abstract WalkingOptions walkingOptions();

abstract Builder usePostMethod(@NonNull Boolean usePost);

abstract Boolean usePostMethod();
Expand Down
Loading