-
-
Notifications
You must be signed in to change notification settings - Fork 77
do not crash demo for GraphHopper rerouting #201
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -187,7 +187,7 @@ class GraphHopperNavigationActivity : | |||||||||||||||||||||
| // Create request object. Requires graphhopper_url to be set in developer-config.xml | ||||||||||||||||||||||
| val request = Request.Builder() | ||||||||||||||||||||||
| .header("User-Agent", "MapLibre Android Navigation SDK Demo App") | ||||||||||||||||||||||
| .url(getString(R.string.graphhopper_url)) | ||||||||||||||||||||||
| .url(getString(R.string.graphhopper_url) + "?key=" + getString(R.string.graphhopper_key)) | ||||||||||||||||||||||
| .post(requestBodyJson.toRequestBody("application/json; charset=utf-8".toMediaType())) | ||||||||||||||||||||||
| .build() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -215,11 +215,12 @@ class GraphHopperNavigationActivity : | |||||||||||||||||||||
| .first() | ||||||||||||||||||||||
| .copy( | ||||||||||||||||||||||
| routeOptions = RouteOptions( | ||||||||||||||||||||||
| // See ValhallaNavigationActivity why these dummy route options are necessary | ||||||||||||||||||||||
| baseUrl = "https://valhalla.routing", | ||||||||||||||||||||||
| profile = "valhalla", | ||||||||||||||||||||||
| user = "valhalla", | ||||||||||||||||||||||
| accessToken = "valhalla", | ||||||||||||||||||||||
| // Used for rerouting. See #201. | ||||||||||||||||||||||
| // TODO: problematic as not the original POST request is used, see #168 | ||||||||||||||||||||||
| baseUrl = getString(R.string.graphhopper_url), | ||||||||||||||||||||||
| profile = "car", | ||||||||||||||||||||||
| user = "gh", | ||||||||||||||||||||||
| accessToken = "pk." + getString(R.string.graphhopper_key), | ||||||||||||||||||||||
|
Comment on lines
+220
to
+223
|
||||||||||||||||||||||
| baseUrl = getString(R.string.graphhopper_url), | |
| profile = "car", | |
| user = "gh", | |
| accessToken = "pk." + getString(R.string.graphhopper_key), | |
| // Use Mapbox-compatible settings so NavigationRoute/MapboxDirections | |
| // constructs syntactically valid reroute URLs, with a dummy token. | |
| baseUrl = "https://api.mapbox.com/", | |
| profile = "driving", | |
| user = "mapbox", | |
| accessToken = "pk.00000000000000000000000000000000", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,10 @@ task accessToken { | |
| " <!-- Your valhalla url (example: https://valhalla1.openstreetmap.de/route) -->\n" + | ||
| " <!-- Don't use the following server in production, it is for demonstration purposes only: -->\n" + | ||
| " <string name=\"valhalla_url\" translatable=\"false\">https://valhalla1.openstreetmap.de/route</string>\n" + | ||
| " <!-- Instead of valhalla you can use GraphHopper for the path finding. Example: https://graphhopper.com/api/1/navigate?key=YOUR_API_KEY or a local server -->\n" + | ||
| " <!-- Instead of valhalla you can use GraphHopper for the path finding. Note that the graphhopper_url has to end with '/'. (#201) -->\n" + | ||
| " <!-- Don't use the following API key in production, it is for demonstration purposes only: -->\n" + | ||
| " <string name=\"graphhopper_url\" translatable=\"false\">https://graphhopper.com/api/1/navigate?key=7088b84f-4cee-4059-96de-fd0cbda2fdff</string>\n" + | ||
| " <string name=\"graphhopper_key\" translatable=\"false\">7088b84f-4cee-4059-96de-fd0cbda2fdff</string>\n" + | ||
| " <string name=\"graphhopper_url\" translatable=\"false\">https://graphhopper.com/api/1/navigate/</string>\n" + | ||
|
Comment on lines
+20
to
+23
|
||
| " <!-- Your Mapbox access token (example: pk.abc...) -->\n" + | ||
| " <string name=\"mapbox_access_token\" translatable=\"false\">" + mapboxAccessToken + "</string>\n" + | ||
| " <!-- Map tile provider for light design (example: https://api.maptiler.com/maps/basic-v2/style.json?key=...) -->\n" + | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Building the GraphHopper request URL via string concatenation is brittle: it will produce an invalid URL if graphhopper_url already contains a query string, and it doesn't URL-encode the key. Prefer constructing the URL with OkHttp's HttpUrl (parse + newBuilder + addQueryParameter) so
keyis appended correctly regardless of trailing slashes or existing parameters.