Time for action - creating the search form

  1. Create a script /path/to/webroot/properties/geo_search.php with the following content:
    <?php
    /**
    * File: /path/to/webroot/properties/geo_search.php
    */
    include('init.php'),
    // Get the data from form (if submitted)
    $latitude = !empty($_POST['latitude']) ? $_POST['latitude'] : '';
    $longitude = !empty($_POST['longitude']) ? $_POST['longitude'] : '';
    $radius = !empty($_POST['radius']) ? $_POST['radius'] : 5;
    // Set the variables for view
    $viewVars['latitude'] = $latitude;
    $viewVars['longitude'] = $longitude;
    $viewVars['radius'] = $radius;
    render('geo_search'),
    
  2. Create the view for the geo search page at /path/to/webroot/properties/views/geo_search.thtml:
    <!-- File: /path/to/webroot/properties/views/geo_search.thtml -->
    <form action="geo_search.php" method="post">
    <fieldset>
    <legend>Geo Location Search</legend>
    <div class="input">
    <label>Latitude: </label>
    <input type="text" name="latitude"
    value="<?php echo $viewVars['latitude']; ?>" />
    </div>
    <div class="input">
    <label>Longitude: </label>
    <input type="text" name="longitude"
    value="<?php echo $viewVars['longitude']; ?>" />
    </div>
    <div class="input">
    <label>Within: </label>
    <select name="radius">
    <?php for ($i = 5; $i <= 30; $i += 5): ?>
    <?php
    $selected = '';
    if ($i == $viewVars['radius']) {
    $selected = ' selected';
    }
    ?>
    <option value="<?php echo $i; ?>"
    <?php echo $selected; ?>>
    <?php echo "$i Kms"; ?>
    </option>
    <?php endfor; ?>
    </select>
    </div>
    <div class="input">
    <label>&nbsp;</label>
    <input type="submit" name="submit" value="Search" />
    </div>
    </fieldset>
    </form>
    

What just happened?

We created a form with fields able to specify the latitude, longitude, and select a radius (in Kilometers). When opened in a browser, the form appears as follows:

What just happened?

Add geo anchor

Now the last step remaining is adding the code to perform a geo distance based search. So let's do it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset