|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Since Google published its Maps API, numerous applications, called mash-ups, have been developed that integrate customized data on top of Google's map interface. With the Maps API, it's straightforward to center a map at a given location, add markers, and display content in info windows—especially if the location is static. However, if the location is driven by user input or retrieved dynamically, the process is somewhat more complex because of the need to geo-code the address.
This article attempts to solve that problem by demonstrating a typical mash-up scenario that integrates an external datasource with Google maps. While the example application we demonstrate here is simplistic and can be completed with fewer steps, the suggested underlying framework can be leveraged to create more robust mash-ups, and should prove useful for those developers looking to integrate external datasources into their existing Java-based Web applications.
Before we get started, let's go over the technologies we will use to set up our mash-up. Google's Maps API is based on coordinates; one must specify the latitude and longitude of a location to show that location on the map. Google's API does not (yet) provide a geo-coding service by which you can show an address on the map directly or translate an address to coordinates. Fortunately, there is a service from geocoder.us that uses public domain data to translate US addresses to coordinates. The geocoder.us service is free for trial use and available for commercial usage for a reasonable fee. The geocoder API is available in various invocation mechanisms, from formal Web services SOAP calls to REST (representational state transfer). While the XML-based remote procedure calls (RPC) and REST-type calls may prove simpler if you are writing the glue-code by hand, the Apache Axis project makes it easy to call SOAP endpoints, so for this article, we use SOAP-based integration.
The Maps API is based on Ajax (asynchronous JavaScript and XML) calls, and cooking up simple applications using only JavaScript proves easy. The API even provides a way of loading data from the application server using Ajax. In our use case, however, the datasource is not local, and for security reasons, XMLHttp, which forms the basis of Ajax, does not allow cross-domain calls. Thus we need to proxy the SOAP call to geocoder.us from our own server.
Finally, an open source library, named DWR (for Direct Web Remoting) practically trivializes the process of connecting the server-side code to client-side JavaScript. We use this library to invoke our GeoCoder Web service proxy methods, get the results, and send that data to the Google Maps API. The overall sequence of events is as follows:
Map mash-up sequence diagram. Click on thumbnail to view full-sized image.
The application (available as a zip file from Resources) is packaged as a standard war file. To run it, drop MapMash.war in the webapps directory of your Jakarta Tomcat installation (or equivalent directory if you use a different servlet container). After you start up the Tomcat server, you will find the application at: http://localhost:8080/MapMash/ (replace the hostname and port as appropriate for your development configuration).
Archived Discussions (Read only)