Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Using HTTP client for Lookup with Google geocode

  1. #1

    Default Using HTTP client for Lookup with Google geocode

    I would like to validate some addresses with Google. The API is pretty simple, here is an example:This is easy to test in any browser.

    It seems like it should be easy to get this to work, but I have a couple of issues that I need to address. I have a job that starts by reading a small text file with a list of addresses.
    Name:  spoon.jpg
Views: 331
Size:  26.9 KB

    I need to pass in a constant sensor=true, so I included an 'add constants' step which adds a field named 'sensor', of type boolean and value of true.

    Next, I add a Modified Java Script Value stage with a simple formula to build an address field from the input text: Here is my Javascript from the 'Script 1' tab:
    String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
    }

    address = StreetAddress.trim() + ", " + City.trim() + ", " +State + " " + PostalCode;
    An example of a generated address is
    41XX FLAMINGO CREST DR UNIT Y, LAS VEGAS, NV 89121
    (I replaced XX and Y by hand)
    So this generates a string that I can pass to HTTP client. Is it safe to assume that the HTTP client will automatically URI encode strings or do I need to explicitly call encodeURIComponent? That is my first question.

    Next, I call HTTP client with:
    Name:  spoon.httpclient.jpg
Views: 345
Size:  28.5 KB
    There are two fields:
    Name:  spoon.httpclient2.jpg
Views: 327
Size:  21.8 KB

    When I run this, I am getting these results for each row:
    {
    ""status"": ""REQUEST_DENIED"",
    ""results"": [ ]
    }
    But I'm stuck here. I dumped the text from this stage into a text file. It looks like sensor=Y. But I need sensor=true to make Google happy. Is there an easy way to see the http request so I can verify that 1) the address is properly encoded and that the sensor value is set as I expect?

    As a side issue, it is possible to load javascript libraries in the Modified Java Script component? After seeing commonjs libraries, I am spoiled and want to be able to load 3rd party libraries so I'm not having to write something like a trim() function in javascript.

  2. #2
    Join Date
    Apr 2008
    Posts
    4,686

    Default

    What happens if you use a string of "true" rather than Boolean True?

    (Short in the dark...)

  3. #3

    Default

    That was all it took. Gutlez, you are a great shot, even in the dark. Thanks

  4. #4
    Join Date
    Apr 2008
    Posts
    4,686

    Default

    I'd be curios to see your JSON path coming out once you have it working (I could really use GeoCoding Lat/Long -> Address)

    Glad I could be of help.

    PS. According to Google, if you are not using a GPS device to obtain the location, you should be sending "false" rather than "true"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.