Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
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
Page 3 of 3
Your application console may warn you about missing items related to Spring, Hibernate, Bean Scripting Framework, JDOM, etc.:
Missing classdef for creator 'spring'. Failed to load uk.ltd.getahead.dwr.create.SpringCreator.
Cause: org/springframework/beans/factory/BeanFactory Missing classdef for creator 'script'.
Failed to load uk.ltd.getahead.dwr.create.ScriptedCreator.
etc..
You can safely ignore these; we are not utilizing these features.
Finally, in the browser, we display a map and an input field for the user to type an address. The Submit button's onclick event invokes the findAddress_onclick() event-handler function, which calls our GeoCoder proxy via DWR to translate the address into latitude/longitude coordinates
and redraws the map accordingly:
function findAddress_onclick() {
var address = document.getElementById("address").value;
// Create an anonymous callback function to manipulate the
// map using the given latitude/longitude coordinates.
var moveMapCallback = function(points) {
if (points.length > 0) {
// In case there are multiple matches, we just use the first.
var point = points[0];
var newCenter = new GPoint(point._long, point.lat);
map.recenterOrPanToLatLng(newCenter);
map.addOverlay(new GMarker(newCenter));
map.openInfoWindow(newCenter,
document.createTextNode("Coordinates: " + newCenter));
document.getElementById("debugGeoCoding").innerHTML= newCenter;
} else {
document.getElementById("debugGeoCoding").innerHTML = 'no match';
}
}
// DWR will proxy this call to GeoCoder's geocode method on the server.
// Once it gets a response, DWR will pass the result as an arg to the callback.
GeoCoder.geocode(address, moveMapCallback);
}
Note that the findAddress_onclick() function passes an anonymous callback function to the DWR-generated GeoCoder.geocode() function. This satisfies the contract with DWR's generated JavaScript; since Ajax is asynchronous, the callback function
is invoked once the call to our GeoCode proxy is completed. The geocode() method in GeoCoder.java returns an array of GeocoderAddressResults, which DWR passes to the callback function as an argument. The callback uses the first GeocoderAddressResult in the passed-in array to manipulate the map by centering to the new coordinates, adding a marker at the new center, and
adding an info window displaying the coordinates.
While the mash-up demonstrated here may be a bit trivial, the framework used to build it can be applied to develop a much more robust application. We've integrated an outside datasource via SOAP, and we have "remotely" invoked our SOAP service using Ajax via the DWR library. This approach can be easily extended to integrate additional data to Google's map interface or to integrate third-party data into your own application.
Read more about Tools & Methods in JavaWorld's Tools & Methods section.
Archived Discussions (Read only)