H DFTACTGRP(*NO) BNDDIR('HTTPAPI') /copy httpapi_h /copy ifsio_h D GEOCODE PR ExtPgm('GEOCODE') D address 32a const D City 32a const D State 32a const D Zip 32a const D GEOCODE PI D address 32a const D City 32a const D State 32a const D Zip 32a const D QCMDEXC PR ExtPgm('QCMDEXC') D command 32702a const options(*varsize) D len 15p 5 const D igc 3a const options(*nopass) D YahooResponse PR D r likeds(resp) D depth 10I 0 value D name 1024A varying const D path 24576A varying const D value 32767A varying const D attrs * dim(32767) D const options(*varsize) * Yahoo! Geocoding Request fields: D req ds qualified inz D appid 96a varying D street 30a varying D city 30a varying D state 20a varying D zip 15a varying D location 100a varying * Yahoo! Geocoding Response fields: D resp ds qualified inz D Latitude 9p 6 D Longitude 9p 6 D Address 30a varying D City 30a varying D State 2a varying D Zip 15a varying D Country 20a varying D errMsg 256a varying D Enc s like(HTTP_URL_ENCODER) D url s 32767A varying D filename s 50a varying D cmd s 200A D msg s 52a D wait s 1a D rc s 10i 0 /free *inlr = *on; if (%parms < 4); http_comp('You must pass ADDRESS, CITY, STATE & ZIP'); return; endif; // FIXME: "req.appid" is the Yahoo Application ID. // You get this when you register with Yahoo! // and you have to tell them about your application // before they'll give it to you. // Go here for details: // http://developer.yahoo.com/faq/index.html#token req.appid = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; req.street = %trim(address); req.city = %trim(city); req.state = %trim(state); req.zip = %trim(zip); req.location = ''; // ******************************************************** // Use the HTTPAPI URL Encoder to create a URL for the // REST web service. // ******************************************************** Enc = http_url_encoder_new(); http_url_encoder_addvar_s( enc: 'appid' : req.appid ); http_url_encoder_addvar_s( enc: 'street' : req.street ); http_url_encoder_addvar_s( enc: 'city' : req.city ); http_url_encoder_addvar_s( enc: 'zip' : req.zip ); http_url_encoder_addvar_s( enc: 'location': req.location ); url = 'http://api.local.yahoo.com/MapsService/V1/geocode?' + http_url_encoder_getstr(enc); http_url_encoder_free(enc); // ******************************************************** // Send request to Yahoo! and get response // ******************************************************** filename = http_tempfile(); rc = http_url_get( url: filename ); if (rc < 1); unlink(filename); http_crash(); endif; /if defined(DEBUGGING) dsply ('Press to see YAHOO response') ' ' wait; cmd = 'DSPF STMF(''' + filename + ''')'; QCMDEXC(cmd: %len(cmd)); /endif // ******************************************************** // Response will be XML. Parse it. // ******************************************************** rc = http_parse_xml_stmf( filename : HTTP_XML_CALC : *null : %paddr(YahooResponse) : %addr(resp) ); unlink(filename); if ( rc < 0 ); http_crash(); endif; // ******************************************************** // For the sake of demonstration, put the results // on the screen... // ******************************************************** if (resp.errMsg <> ''); http_comp(resp.errMsg); return; endif; dsply (' Lat = ' + %char(resp.latitude) ); dsply (' Lon = ' + %char(resp.longitude)); dsply (' Addr = ' + resp.address ); dsply (' City = ' + resp.city ); dsply ('State = ' + resp.state ); dsply (' Zip = ' + resp.zip ); dsply ('Cntry = ' + resp.country ); dsply ('Press to continue') ' ' wait; return; /end-free P YahooResponse B D YahooResponse PI D r likeds(resp) D depth 10I 0 value D name 1024A varying const D path 24576A varying const D value 32767A varying const D attrs * dim(32767) D const options(*varsize) /free if (path = '/ResultSet/Result'); select; when name = 'Latitude'; r.latitude = %dec(value:9:6); when name = 'Longitude'; r.longitude = %dec(value:9:6); when name = 'Address'; r.address = %trimr(value); when name = 'City'; r.city = %trimr(value); when name = 'State'; r.state = %trimr(value); when name = 'Zip'; r.zip = %trimr(value); when name = 'Country'; r.country = %trimr(value); endsl; endif; if ( path = '/Error' ); if ( name = 'Message' ); r.errMsg = %trimr(value); endif; endif; /end-free P E