Friday, May 22, 2009

Auto Complete with AJAX

Its the first time that I have wet my hands with AJAX.(Reference - AJAX/JAVA)Prior to this I have been using .Net AJAX server side controls which internally wrap AJAX calls ,thus letting a user to deal only with facade.
There are numerous utilities to add auto-complete functionality to your site/application.I found them complex to use leading me to write one for myself.
It has three simple steps
1.Make asynchronous call to the server(handled by servlet) using XMLHttpRequest .
2.Get the required data in servlet and send the response as XML
3.Grab and process the data(display) in the front end when control is returned from the server.
The above three steps are common for any functionality achieved using AJAX.
The jsp page looks like this


In the above jsp if you have seen, on "onkeyupevent", function getData is called passing in the 4 parameters.The javascript file(its in text format) can be downloaded here
The servlet which handles the synchronous call made by jsp is shown below.The data to to be loaded is initialized by overriding the init method of the servlet(data retrieval will vary according to ones need)



That is pretty much.There is definitely a huge room for improvement but its gets the target rolling.

NOTE:The blogger.com parses everything ,so I had to include code in images.If anybody knows a better way to include code in blogspot, will be great.Thanks

Monday, May 11, 2009

Know your co-ordinates

Geolocation recently caught my attention, so thought of dabbling with it.There are numerous tools available to get the geo location but the one I tried is Google Geolocation.It is one of the AJAX APIs provided by google(reference Maps Basics, Developer's guide, Thasha's blog).

It deviates from actual longitude/latitude of the place when it depicts the place on the map.

I couldn't place it any where but at the bottom of my blog.Please scroll down to see the Google API(geolocator) in action

Co-ordinates tuned
I spend some time on Google Map API and learnt some more features about it. One can add overlays on the map based on the data(addresses) one has.Though google already provides feature of showing myriad utilities(hospitals. schools etc etc) on the map, but this will be handy when one's data is more customised and changes frequently.
As I have written earlier that the co-ordinates as calculated by the API vary a little , so I have added correction of point something to the latitude and longitude,that gives better results

Assumptions of linear regression

There are some assumptions that a OLS (ordinary least square) or  linear regression makes about data and if these assumptions are not satisf...