How to retrieve data from Google api?

Hi all,

I am trying to get the longitude and latitude from google by sending them an address. I have sub-classed HTTPSecureSocket with a PageReceived event. I call the api this way:

dim address as string = "2 On Yiu Street, Shatin"
dim key as string = <my key>
dim url as string = "https://maps.googleapis.com/maps/api/geocode/json?address=" + address + "&key=" + key

dim socket1 as new MyClass1
socket1.get(url)

In the PageReceived event, I got Error 400 (Bad Request) … But if I open the url in chrome, it returns the right data that I want. Please help.

Replace spaces in the address by %20
This worked for me:

[code]dim address as string = replaceall(“2 On Yiu Street, Shatin”," “,”%20")
dim key as string = “AIzaSyBVweBiNsm4-o27Ui0vmB4sboBGFGrv_FA”
dim url as string = “https://maps.googleapis.com/maps/api/geocode/json?address=’” + address + “’&key=” + key

dim h as new HTTPSecureSocket
h.yield = true
dim x as string
x= h.get (url,2)
msgbox x[/code]

Thanks Jeff

Is it free to use ?

I suspect that is a private key.
If so, this thread should be hidden. :slight_smile:

https://developers.google.com/maps/documentation/javascript/get-api-key

Use the EncodeURLComponent method rather than ReplaceAll. It will handle spaces as well as other reserved characters:

dim address as string = EncodeURLComponent("2 On Yiu Street, Shatin")