How to retrieve data from Google api?

  1. 5 weeks ago

    Tony L

    Jun 11 Pre-Release Testers, Xojo Pro Hong Kong
    Edited 5 weeks ago

    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.

  2. Jeff T

    Jun 12 Midlands of England, Europe

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

    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
  3. Tony L

    Jun 12 Pre-Release Testers, Xojo Pro Hong Kong

    Thanks Jeff

  4. Joost R

    Jun 12 Pre-Release Testers, Xojo Pro The Netherlands

    @Jeff T dim key as string = "AIzaSyBVweBiNsm4-o27Ui0vmB4sboBGFGrv_FA"

    Is it free to use ?

  5. Jeff T

    Jun 12 Midlands of England, Europe

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

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

  6. Andrew L

    Jun 12 San Francisco, CA, USA

    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")

or Sign Up to reply!