Topic
  • 5 replies
  • Latest Post - ‏2013-03-27T16:40:23Z by dan_darnell
huub100759
huub100759
48 Posts

Pinned topic GoogleMaps APi Json

‏2013-03-26T11:11:12Z |
I want to implement the REST/JSON version of the GoogleMap APi

(http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false)

Can anyone help me out here, how to do this?
I m using RBD 8.0.1.3. with Tomcat 6

Thanks in advance

Huub
Updated on 2013-03-27T16:40:23Z at 2013-03-27T16:40:23Z by dan_darnell
  • markevans
    markevans
    2850 Posts

    Re: GoogleMaps APi Json

    ‏2013-03-26T14:12:22Z  
    Huub,

    Not sure this is what you are looking for, but check out the EGL Tutorial on creating a mortgage application that includes invoking the Google map APIs.

    http://publib.boulder.ibm.com/infocenter/rbdhelp/v8r0m0/index.jsp?topic=%2Fcom.ibm.egl.richui.mortgage.tutorial.doc%2Ftopics%2Fegl_richui_mortgage_intro.html

    Specifically see lesson 10.

    take care.
  • huub100759
    huub100759
    48 Posts

    Re: GoogleMaps APi Json

    ‏2013-03-26T14:15:00Z  
    Hi Mark

    Thanks for your response.
    But this is not what i am looking for.
    I need information how to implement the REST-service.
    And use the result in JSON format.

    Thanks again

    Huub
  • dan_darnell
    dan_darnell
    973 Posts

    Re: GoogleMaps APi Json

    ‏2013-03-26T16:46:52Z  
    Hi Mark

    Thanks for your response.
    But this is not what i am looking for.
    I need information how to implement the REST-service.
    And use the result in JSON format.

    Thanks again

    Huub
    Hi Huub,

    I see that you are trying to use the geocoder rather than the actual map API. I have experience with that...

    I'm not using JSON for the response format. For reasons I no longer remember I found it better to use the CSV format on the return. Maybe the code below will help you move forward...

    
    
    
    interface GoogleCoderService   function geo(q string in, output string in, oe string in, sensor string in, key string in) returns (string) 
    {@GetRest 
    { uriTemplate=
    "http://maps.google.com/maps/geo?q={q}&output={output}&oe={oe}&sensor={sensor}&key={key}", responseFormat = NONE 
    }
    };   end
    

    In my Rich UI client:

    
    
    
    private googleCoderService GoogleCoderService 
    {@RestBinding 
    {
    }
    };
    


    
    
    // Call this function for every address that I want to geocode... 
    
    private function process(address string in) output string = 
    "csv"; oe string = 
    "utf8"; sensor string = 
    "false";   
    // My unique Google API key (provided by Google): key string = 
    "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; call googleCoderService.geo(address, output, oe, sensor, key) returning to processReturn onException exceptionHandler; end   
    
    private function processReturn(result string in)   
    // Tokenize CSV results from geocoder call result = result + 
    ","; 
    // Add final delimiter to make my tokenizing life easier delimiters STRING = 
    ","; i INT = 1; max INT; tokens STRING[0]; token STRING? = 
    ""; numberOfTokens 
    
    int = 0;   max = strlib.characterLen(result); 
    
    while( i > 0) token = 
    
    null; start 
    
    int = i; i = strlib.indexOf(result, delimiters, i); 
    
    if (i > 0 and i > start) token = result[start:i-1]; i += 1; end 
    
    if (token != 
    
    null) tokens.appendElement(token); numberOfTokens += 1; end end   googleLocation GoogleCoderLocation; 
    
    if(numberOfTokens >= 4) 
    
    if(tokens[1] == 
    "200") googleLocation.accuracy = tokens[2]; googleLocation.latitude = tokens[3]; googleLocation.longitude = tokens[4]; end 
    
    else 
    // Something really bad happened...not enough tokens returned...do something? end   
    // At this point you have a "googleLocation" record that contains the results 
    //  of the geocoder call. Or, if the "something really bad happened" happened  
    //  then everything in the record is blank.   end
    


    Format of location record:
    
    record GoogleCoderLocation type BasicRecord accuracy string; latitude string; longitude string; end
    


    Note: No entries are required in the deployment descriptor for the service invocation since we provide the full URL in the interface definition.

    The code above is part of a little app I wrote that reads a database of addresses and geo-codes everything in the database. It displays the addresses in a grid and processes the grid data using a Job on a short timer so that Google doesn't get unhappy about too many requests coming in too quickly. Unless they've changed things you also have to deal with a daily limit on geo-coding requests.

    Hope this helps...

    --Dan
  • huub100759
    huub100759
    48 Posts

    Re: GoogleMaps APi Json

    ‏2013-03-26T18:30:28Z  
    Hi Huub,

    I see that you are trying to use the geocoder rather than the actual map API. I have experience with that...

    I'm not using JSON for the response format. For reasons I no longer remember I found it better to use the CSV format on the return. Maybe the code below will help you move forward...

    <pre class="jive-pre"> interface GoogleCoderService function geo(q string in, output string in, oe string in, sensor string in, key string in) returns (string) {@GetRest { uriTemplate= "http://maps.google.com/maps/geo?q={q}&output={output}&oe={oe}&sensor={sensor}&key={key}", responseFormat = NONE } }; end </pre>
    In my Rich UI client:

    <pre class="jive-pre"> private googleCoderService GoogleCoderService {@RestBinding { } }; </pre>

    <pre class="jive-pre"> // Call this function for every address that I want to geocode... private function process(address string in) output string = "csv"; oe string = "utf8"; sensor string = "false"; // My unique Google API key (provided by Google): key string = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; call googleCoderService.geo(address, output, oe, sensor, key) returning to processReturn onException exceptionHandler; end private function processReturn(result string in) // Tokenize CSV results from geocoder call result = result + ","; // Add final delimiter to make my tokenizing life easier delimiters STRING = ","; i INT = 1; max INT; tokens STRING[0]; token STRING? = ""; numberOfTokens int = 0; max = strlib.characterLen(result); while( i > 0) token = null; start int = i; i = strlib.indexOf(result, delimiters, i); if (i > 0 and i > start) token = result[start:i-1]; i += 1; end if (token != null) tokens.appendElement(token); numberOfTokens += 1; end end googleLocation GoogleCoderLocation; if(numberOfTokens >= 4) if(tokens[1] == "200") googleLocation.accuracy = tokens[2]; googleLocation.latitude = tokens[3]; googleLocation.longitude = tokens[4]; end else // Something really bad happened...not enough tokens returned...do something? end // At this point you have a "googleLocation" record that contains the results // of the geocoder call. Or, if the "something really bad happened" happened // then everything in the record is blank. end </pre>

    Format of location record:
    <pre class="jive-pre"> record GoogleCoderLocation type BasicRecord accuracy string; latitude string; longitude string; end </pre>

    Note: No entries are required in the deployment descriptor for the service invocation since we provide the full URL in the interface definition.

    The code above is part of a little app I wrote that reads a database of addresses and geo-codes everything in the database. It displays the addresses in a grid and processes the grid data using a Job on a short timer so that Google doesn't get unhappy about too many requests coming in too quickly. Unless they've changed things you also have to deal with a daily limit on geo-coding requests.

    Hope this helps...

    --Dan
    Dan, You are the man!!! (as allways..)
    It works! , I will post the JSON-solution when i got it all figured out.
    By the way: are there plans for another EGLCON??????

    Thank you very much

    Huub Keulartz
    QNH Consulting Zuid
    The netherlands
  • dan_darnell
    dan_darnell
    973 Posts

    Re: GoogleMaps APi Json

    ‏2013-03-27T16:40:23Z  
    Dan, You are the man!!! (as allways..)
    It works! , I will post the JSON-solution when i got it all figured out.
    By the way: are there plans for another EGLCON??????

    Thank you very much

    Huub Keulartz
    QNH Consulting Zuid
    The netherlands
    Glad that worked for you. If you go JSON with it please do post the code...I'd like to have that in my back pocket.

    I'm not an IBM'er but my guess is that we won't be seeing any more EGLCONs or anything else of the sort unless/until the global economy picks up.

    --Dan