Databases Reference
In-Depth Information
l address item val := v(l address item);
IF l address item val IS NULL
THEN
clear lat long;
If the address item's session state value is not null, then processing continues. Parameters for the
Yahoo API are set up. Because carriage returns can cause issues when making web service requests, they
are stripped from the address value.
ELSE
l parm name list(1) := 'appid';
l parm value list(1) := l yahoo appid;
l parm name list(2) := 'flags';
l parm value list(2) := 'C'; --Only return coordinate data and match quality elements
l parm name list(3) := 'location';
l parm value list(3) := REPLACE(REPLACE(l address item val, CHR(13)||CHR(10), ' '),
CHR(10), ' ');
The APEX WEB SERVICE.MAKE REST REQUEST function is used to make the call to Yahoo's API. Because
the result of that function is a CLOB, XMLTYPE is used to convert the result to an XMLTYPE object.
l rest result := xmltype(
apex web service.make rest request(
p url => 'http://where.yahooapis.com/geocode',
p http method => 'GET',
p parm name => l parm name list,
p parm value => l parm value list
)
);
The resulting XML is first checked for errors. If no errors are found then the XML is checked for the
number or results. If only one result was retrieved then it is checked for accuracy. If the accuracy of the
result is equal to or above 87 out of 100 then the values of the latitude and longitude items are set from
the result. If multiple results were retrieved or if the accuracy is too low then the values of the latitude
and longitude items are cleared.
IF l rest result.extract('//Error/text()').getnumberval() = 0
THEN
l found count := l rest result.extract('//Found/text()').getnumberval();
IF l found count = 1
THEN
IF l rest result.extract('//Result/quality/text()').getstringval() >= 87
--Address match with street match (or better)
THEN
apex util.set session state(l lat item, l rest result.extract
('//Result/latitude/text()').getstringval());
apex util.set session state(l long item, l rest result.extract
('//Result/longitude/text()').getstringval());
ELSE
Search WWH ::




Custom Search