This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

urlencoding the street and address parameters for Nominatim breaks response

0

Not sure what's going on, but if I make a request to Nominatim from the browser for this address ( 5145 Beltway Drive, Grand Rapids ) like this then it work fine, but if I do it through php and wrap the city and street details in urlencode, then I get no response.

The encoded URL format is this, but somehow this is not accepted. The http response is 200, so that's not the issue.

Does it simply not accept encoded data? I can't find anything about it in the documentation.

asked 08 Jun '20, 19:09

Tijmens's gravatar image

Tijmens
16113
accept rate: 0%


One Answer:

3

The urlencode of a full URL also encodes = (as %3D) and I think &, too . What you probably want to do is urlencode the values only. E.g.

$street = '5145 Beltway Drive';
$city = 'Grand Rapids';
$url = 'https://nominatim.openstreetmap.org/search?street='.urlencode($street).'&city='.urlencode($city).'&format=json&addressdetails=1&limit=1';

For best results I suggest using the unstructured query format and add the country if possible. jsonv2 format also has a couple of additional field.

$address = $street . ', ' . $city . ', USA';
$url = 'https://nominatim.openstreetmap.org/search?q='.urlencode($address).'&format=jsonv2&addressdetails=1&limit=1';

answered 08 Jun '20, 20:37

mtmail's gravatar image

mtmail
4.8k1574
accept rate: 27%

edited 08 Jun '20, 20:37

Source code available on GitHub .