The geocoder is an address search. We wrote a separate program (CGI) to handle the geocoding because GeoServer cannot handle that type of request. Geocoding is not part of the WFS specification.
The geocoder also works against the TIGER roads dataset (the geographic search worked against the GNIS dataset).
On the server-side, there is the CGI script waiting for a request to come in. It will parse the request, do its best to find the address, and then return the results in the form of an <ogc:FeatureCollection> XML response document.
On the client-side, we pretty much just copy and paste everything that we did for the geographic search.
The search is still AJAX and the results are handled the same.
The URL for the request is different this time around. We need to send the request to the CGI script, not GeoServer. So the URL looks like this: http://sigma.openplans.org/cgi-bin/geocoder.cgi
The XML request is also slightly different. It is our own handmade request format that looks like a getFeature request:
With the new URL and the new XML request, we follow the same steps to send off our request to the server, and wait for a response:
Our XML Progress function is almost exactly the same as the geographic search one. We just have to walk through the returned result differently. The result will follow this format:
To walk the XML structure, so we can grab the results information, we use the same getElements() function as before:
Result box
I made a result box, exactly the same as the one for the geographic search, for the geocoder and placed it right under the geocoder form.
At this point, I also made it so that when a person searches using the geocoder, it hides the geographic search results box. And when they perform a geographic search, it hides the geocoder search results box. This makes the page much more readable and user friendly.
To hide the boxes, you can just set the style "display:none". I didn't know this at the time so I swapped out the HTML in the <div> containing the results box. I left it in as an example of another way to do it. Below, you can see that to hide the result boxes, I just searched for them, and set their innerHTML to blank:
How the CGI script works - by Dave Blasby
TODO: here you go dave
SUMMARY
First, we copied the geographic search request code and result parsing code.
Then we changed the URL of the request to point to the geocoder CGI script. And also changed the request XML.
After, we changed the result parsing code to handle the result returned from the server.
Finally, we made another result box, exactly the same as the geographic search one, and put the geocoder results in it.
>>Proceed onto the next step, Step 7: Bookmarking >>