Simple City Search

A very simple City Search Code Example, using the GeoNames Fulltext Service. Please view the Service Documentation for this service to examine the query defaults.

1. Install the 'GeoNames API' and 'search' modules on your site.
2. Create a new page on your site, and set Input format to PHP code.
3. Add the following code to the page:

<form method=post>
<input type=hidden name=style value=medium>
City Search <input type=text name=name>
<input type=submit>
</form>

<?php
$result = geonames_query('search', $_POST);
if ($result->total_results_count) {
  print theme('geonames_table', $result);
}
?>

Example Result: City Search
Explanation:
the <form... .../form> is HTML and displays the form field and submit button. It also sets the request style to medium (other options for style are short, long and full).

The PHP code posts the form values as the query array ($_POST) and the geonames_query function uses the 'search' module to find the results. If we get results ($results->total_results_count), the theme('geonames_table', $result) function prints a nice table from the result object ($result) unless you have requested too much information ;).

Hello, Thanks for this page

Hello,

Thanks for this page and GeoNames porting on Drupal. It's going to be great if I get it up and run !
But for now I can't even get this simple example to work.

Basically, I'm looking for a way to find the nearest address on adding a tag on the map and the same the other way (address translated to tag). (my big problem : I am not really a programmer)

Is there a clear example with drupal and address ? Is the upper example compatible with Drupal 6 ? Any ideas of why it is not working ?

Thanks in advance.
Michael

Syndicate content