Creating an Address Search in APEX
I recently had a request to implement a comprehensive UK address search in an APEX application without using a dedicated API such as the Royal Mail PAF. The first place I looked was obviously the Google Maps API, and while Google APIs make up part of my solution, I had to take a few extra steps to get there.
The first set of search results managed to generate were from the Google Places API. This allowed me to pass search terms from my application and receive an XML list of relevant business addresses and places of note that match the search. I could also pass co-ordinate boundaries to the API to limit the search to the UK only.
Using in-built PL/SQL XML packages I was able to pick out the XML nodes I needed and piece together addresses to add to my search results which I stored in an APEX collection.
Although this worked well, the client required to be able to search residential addresses alongside business and place addresses. This was possible by making a call to the Google Geocode API. By sending a request to this API along with the same boundaries, I was able to receive an XML list of different search results, including residential addresses. These results were returned in a slightly different format, so after a little piecing together, I was able to add them to the collection.
Further to this, I included a lookup of addresses stored in the database and added any positive results to the collection. The collection is displayed in a modal popup after pressing the search button. Clicking an address in the search results populates the address field on the application and closes the modal popup.
To accompany the search results I used the Google Static Maps API to display a map of any selected address with a marker showing the location.
This isn’t a perfect solution, but it includes 99% of the addresses the client needs and any addresses not found in the search results can be entered manually by the user and will then show up in any future searches. This solution offers fast, relevant search results within APEX without having to subscribe to a dedicated address search API and implemented alongside modal popups and dynamic region refreshes, provides a pretty nice looking end result.
Craig is a Senior Development Consultant at Explorer. Craig has an MSc in Computing Science and is an experienced software engineer, utilising development tools such as PL/SQL and APEX to provide bespoke ERP software to both UK and international businesses. Craig has experience developing solutions to connect Oracle systems to a wide range of existing external applications within business environments.