GIScience / openrouteservice-js

:pushpin: The JavaScript API to consume openrouteservice(s) painlessly!
https://openrouteservice.org
Apache License 2.0
191 stars 35 forks source link

bug: Cannot get geocoding for some adresses #37

Closed busybox11 closed 2 years ago

busybox11 commented 2 years ago

Hey, I've recently discovered this module that is just amazing, first thing first, thanks to y'all guys, this is genuinely awesome and this is a great example of why the open source community is awesome, writing all the requests manually would have been a HUGE pain.

I have a problem with the Geocoding API tho. I'm trying to get the results for a string. I can't provide it to you guys because it contains private information, but I'm trying to find an example I could use that has the same behavior as mine.

Sometimes, especially with accented strings apparently, the geocoder doesn't get the address right and the parsing isn't done properly, which results in no point data at all. After further debugging, I eventually noticed the parser was faulty, because the API returned an URI-encoded string in the result["geocoding"]["query"]["text"] element. Though, apparently only accented characters get URI-encoded, since spaces and special characters aren't. I tested this on OpenROuteService's website and it does work, here the whole string is encoded, not just parts of it. In my script, the used parser is pelias, whereas on the website it is libpostal. pelias doesn't recognize anything at all while libpostal is able to determine how is the address string composed.

I hope my explanation is clear and that you will be able to help me solve this problem. In the meantime I'm trying to get it working by myself, if I find anything I'll update you from this issue. Thanks again and good night! :)

chris-gassner commented 2 years ago

I ran into a similar issue, when looking for addresses with the 'ß' character. I was not getting any results while I got results perfectly fine via the api playground on the homepage. The problem seems to be with the encoding of the special characters. I managed to get it to work by first decoding the search strings and reencoding them with the encodeURIComponent function.

amoncaldas commented 2 years ago

Fixed in https://github.com/GIScience/openrouteservice-js/tree/v0.1.31