Package globus.glroute
Class GLRouteRequest
java.lang.Object
globus.glmap.GLNativeObject
globus.glroute.GLRouteRequest
Builds and executes online or offline route requests (Valhalla-based).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback invoked when a route request finishes. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructorGLRouteRequest(String userJSON) Constructor with custom json request to valhalla -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExcludeLocation(GLRoutePoint point) A location to exclude or avoidvoidaddExcludePolygon(MapGeoPoint[] points) Roads intersecting this polygon will be avoided during path finding.voidaddPoint(GLRoutePoint point) Adds pointstatic intbikeTypeFromString(String type) Converts the string representation of BikeType to its valuestatic StringbikeTypeToString(int type) Converts BikeType to its string representationstatic voidcancel(long requestID) Cancels a request started viastartOnline(ResultsCallback)orstartOffline(String, ResultsCallback).intGet number of alternatesgetJson()Retrieves the JSON request that will be sent to Valhalla.Retrieves the locale used for route instructions.intgetMode()Retrieves the mode of the route.booleanRetrieves the current value of the optimize setting.intRetrieves the unit system used for route instructions.static ObjectofflineActionOrError(String action, String request, String config, MapGeoPoint startPoint) Starts a synchronous offline Valhalla request.voidsetAlternates(int alternates) A number denoting how many alternate routes should be provided.voidsetAutoWithOptions(CostingOptions.Auto options) Sets navigation mode to autovoidSets navigation mode to cyclevoidSets navigation mode to bikesharevoidsetBusWithOptions(CostingOptions.Auto options) Sets navigation mode to busvoidSets the locale for route instructions.voidSets navigation mode to motorcyclevoidSets navigation mode to scootervoidsetOptimize(boolean optimize) Sets whether the order of middle points can be optimized to create a faster route.voidSets navigation mode to walkvoidsetRequestID(String requestID) Name your route request.voidSets navigation mode to straightvoidsetTaxiWithOptions(CostingOptions.Auto options) Sets navigation mode to taxivoidsetTruckWithOptions(CostingOptions.Truck options) Sets navigation mode to truckvoidsetUnitSystem(int unitSystem) Sets the unit system for route instructions.longstartOffline(String config, GLRouteRequest.ResultsCallback callback) Starts an offline route request.longstartOnline(GLRouteRequest.ResultsCallback callback) Starts an online route request.Methods inherited from class globus.glmap.GLNativeObject
dispose
-
Constructor Details
-
GLRouteRequest
public GLRouteRequest()Default constructor -
GLRouteRequest
Constructor with custom json request to valhalla- Parameters:
userJSON- json request to valhalla
-
-
Method Details
-
startOnline
Starts an online route request.The callback may be invoked on a background thread.
- Parameters:
callback- results callback- Returns:
- id of task
-
startOffline
Starts an offline route request.The callback may be invoked on a background thread.
- Parameters:
config- Contents of configuration file for routing engine Valhalla. See valhalla3.json inside the demoApp.callback- results callback- Returns:
- id of task
-
offlineActionOrError
@Nullable public static Object offlineActionOrError(@NonNull String action, @NonNull String request, @NonNull String config, @Nullable MapGeoPoint startPoint) Starts a synchronous offline Valhalla request.- Parameters:
action- Valhalla action (e.g."route","optimized_route", …).request- JSON string with the request payload.config- Contents of the Valhalla configuration file (seevalhalla.jsonin the demo app).startPoint- Optional starting point in degrees used to speed up offline data lookup (passnullto skip).- Returns:
- A JSON string with the response on success or a
GLMapErrorinstance on failure.
-
cancel
public static void cancel(long requestID) Cancels a request started viastartOnline(ResultsCallback)orstartOffline(String, ResultsCallback).Cancellation is best-effort; already running work may still complete and invoke callbacks.
- Parameters:
requestID- ID of request to cancel
-
addPoint
Adds point- Parameters:
point- point to add
-
addExcludeLocation
A location to exclude or avoid- Parameters:
point- point to add
-
addExcludePolygon
Roads intersecting this polygon will be avoided during path finding. If you only need to avoid a few specific roads, it's much more efficient to use exclude locations.- Parameters:
points- points of polygon exterior ring
-
setRequestID
Name your route request. If an ID is specified, the name will be sent through to the response.- Parameters:
requestID- request id
-
setAutoWithOptions
Sets navigation mode to auto- Parameters:
options- options
-
setBicycleWithOptions
Sets navigation mode to cycle- Parameters:
options- options
-
setPedestrianWithOptions
Sets navigation mode to walk- Parameters:
options- options
-
setStraightWithOptions
Sets navigation mode to straight- Parameters:
options- options
-
setBusWithOptions
Sets navigation mode to bus- Parameters:
options- options
-
setTruckWithOptions
Sets navigation mode to truck- Parameters:
options- options
-
setTaxiWithOptions
Sets navigation mode to taxi- Parameters:
options- options
-
setMotorScooterWithOptions
Sets navigation mode to scooter- Parameters:
options- options
-
setMotorcycleWithOptions
Sets navigation mode to motorcycle- Parameters:
options- options
-
setOptimize
public void setOptimize(boolean optimize) Sets whether the order of middle points can be optimized to create a faster route.By default, this option is
false.- Parameters:
optimize-trueto allow reordering middle points for a better route,falseotherwise.
-
getOptimize
public boolean getOptimize()Retrieves the current value of the optimize setting.- Returns:
trueif middle points can be reordered,falseotherwise.
-
getMode
public int getMode()Retrieves the mode of the route.By default, the mode is
GLRoute.Mode.AUTO.- Returns:
- The mode of the route, defined by
GLRoute.Mode.
-
setUnitSystem
public void setUnitSystem(int unitSystem) Sets the unit system for route instructions.By default, the unit system is
GLMapLocaleSettings.UnitSystem.International.- Parameters:
unitSystem- The unit system to use for instructions, defined byGLMapLocaleSettings.UnitSystem.
-
getUnitSystem
public int getUnitSystem()Retrieves the unit system used for route instructions.- Returns:
- The current unit system, defined by
GLMapLocaleSettings.UnitSystem.
-
setLocale
Sets the locale for route instructions.By default, the locale is set to
Locale.getDefault().getLanguage().- Parameters:
locale- The locale to use for instructions, represented as a language code (e.g., "en", "fr").
-
getLocale
Retrieves the locale used for route instructions.- Returns:
- The locale for instructions, represented as a language code.
-
getJson
Retrieves the JSON request that will be sent to Valhalla.- Returns:
- A JSON string representing the route request.
-
setAlternates
public void setAlternates(int alternates) A number denoting how many alternate routes should be provided. There may be no alternates or less alternates than the user specifies. Alternates are not yet supported on multipoint routes (that is, routes with more than 2 locations). They are also not supported on time dependent routes. By default = 2- Parameters:
alternates- alternates to set
-
getAlternates
public int getAlternates()Get number of alternates- Returns:
- number of alternates
-
bikeTypeToString
Converts BikeType to its string representation- Parameters:
type- type to convert- Returns:
- string representation of type
-
bikeTypeFromString
Converts the string representation of BikeType to its value- Parameters:
type- type to convert- Returns:
- value
-