MKergall / osmbonuspack

A third-party library of (very) useful additional objects for osmdroid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting an invalid URL response

Yotas01 opened this issue · comments

I tried getting a route between 2 points using the RoadManager but I keep getting the same error on my LogCat
2021-11-05 09:50:21.297 17687-17687/main.cityshare D/BONUSPACK: OSRMRoadManager.getRoad:http://router.project-osrm.org/viaroute?&loc=41.910421539499495,12.489872574806213&loc=41.889467,12.492081&instructions=true&alt=false 2021-11-05 09:50:21.668 17687-17687/main.cityshare E/BONUSPACK: Invalid response from server: HTTP/1.1 400 Bad Request 2021-11-05 09:50:21.669 17687-17687/main.cityshare E/BONUSPACK: OSRMRoadManager::getRoad: request failed.
When I follow the URL in a browser I get the following response {"message":"URL string malformed close to position 9: \"ute?&l\"","code":"InvalidUrl"}
I have in my Manifest that android:usesCleartextTraffic="true" and in the OnCreate of the Activity I am using the StrictMode Policy just like in the tutorial 0. Any ideas why I am getting a bad request?

I know this doesn't answer your question, but FYI, you shouldn't be "using the StrictMode Policy just like in the tutorial 0".

For clarity and simplicity, in these tutorials, we do all API calls in the main thread.

Normally, for network calls, this is not recommended at all: we should use threads and asynchronous tasks. Even worse, since Honeycomb SDK (3.0), it is not allowed to make a network call in the main thread: thanks to the "StrictMode.ThreadPolicy" default settings, a NetworkOnMainThreadException exception will be raised.

So:

For these tutorials, either target an SDK earlier than 3.0, or disable the StrictMode policy in onCreate, this way:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);

Use your own threads instead.