0

I am calling this api url with golang:

http://nominatim.openstreetmap.org/search?format=json&addressdetails=0&q=1322%20Kenwood%20Ave.%20Springfield%20OH%2045505%20US

When you click the url you get a single valid response from open street maps.

When I call from golang, I get 10 results back, which are all invalid.

My code looks like:

var myResponse []OpenStreetMapResponse
request, err := http.NewRequest("GET", serviceUrl, nil)
request.Header.Set("Content-Type", "application/json")
client := &http.Client{}
response, err := client.Do(request)
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
json.Unmarshal(body, &myResponse)

what am i doing wrong? this makes absolutely no sense. i can write this api call in about 4 different programming languages and I get the correct response, but golang is giving COMPLETELY different results. any help you can provide would be greatly appreciated.

  • Seems to work for me. What's your `OpenStreetMapResponse` definition? – Ainar-G Jan 27 '16 at 13:05
  • Can you provide the struct for `OpenStreetMapResponse`? – Endre Simo Jan 27 '16 at 13:06
  • Worked for me, what is your serviceURL? Seems like you may be stripping the query string from the URL possible? – Leo Correa Jan 27 '16 at 13:37
  • Why are you setting the `Content-Type` in the request (but send a nil body which is fine)? Maybe you should set `Accept` and/or other headers? And: Check and handle all errors. – Volker Jan 27 '16 at 14:20
  • Is [this](http://nominatim.openstreetmap.org/search?format=json&addressdetails=0&q=1322) the result that you're observing? ;-) – thwd Jan 27 '16 at 14:38
  • thwd that is the result set I'm getting back. I'm expecting the result you get when you click on the link. – C. Blair Jan 27 '16 at 23:22
  • Leo Correa, my service url is what is pasted at the beginning of this post. It is the exact url generated from my code. I'll also have to post of the OpenStreetMapResponse shortly. – C. Blair Jan 27 '16 at 23:25
  • I cant write a full answer right now but your problem is the URL-encoding of `serviceUrl`. Happy hacking! – thwd Jan 28 '16 at 09:37
  • I originally tried url.queryescape to no avail, but got it to work by building the url, its path and params with the url object. Thank You for pushing me to look further into the url object. – C. Blair Jan 28 '16 at 13:27

0 Answers0