Geolocation Coding Help

Hi,

I wanted to know how to make 2 mods to the example files that come with the geocoder. The first is the for the proximity search.

Instead of manually searching a zipcode and returning results like the example code does, how can i use a placeholder for the zip and upon loading the page, it will automatically query based on the zipcode on the page and return results? I want the form to submit automatically with placeholder <?php echo $listingRecord['zipcode'] ?> and then return the nearest 10 results.

Second is similar along the lines, but this is for the multiple map listings. Based on the placeholder <?php echo $listingRecord['zipcode'] ?> , the map would show the 10 nearest locations.

Thanks

Re: [Illume Magazine] Geolocation Coding Help

By Jason - June 7, 2011

Hi,

It looks like you'd want to use the sample_search.php code for both of these cases.

First, when you can do is remove the actual form and change the code so that it does a search without a form submitting. Finally you can limit the query to return only the first 10 record.

As an example:

<?php

$kmOrMiles = 'miles'; // can be 'miles' or 'km'

// set default values
if (!array_key_exists('fromAddress', $_REQUEST)) { $_REQUEST['fromAddress'] = '10001'; } // this is the default address/postalcode if none entered
if (!@$_REQUEST['maxDistance']) { $_REQUEST['maxDistance'] = '50000'; } // this will include all results

$_REQUEST['fromAddress'] = ""; // The ZIP code you want to use goes here
// get coordinates
list($myLat, $myLng) = geocodeAddress( @$_REQUEST['fromAddress'] );

// error checking
$errorsAndAlerts = '';

if (!$myLat || !$myLng) { $errorsAndAlerts .= "We couldn't determine your location, please try again!<br/>\n"; }


// get records
$addressRecords = array();
if ($myLat && $myLng) {
$maxDist = floatval(@$_REQUEST['maxDistance']);
list($addressRecords, $addressMetaData) = getRecords(array(
'tableName' => $GLOBALS['GEOCODER_SAMPLE_TABLENAME'],
'addSelectExpr' => geocoder_getSelectExprForDistance($myLat, $myLng, '_distance', $kmOrMiles), // adds '_distance' field to output records
'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles), // optimization: remove results outside of minimum bounding rectangle
'having' => "_distance <= " . $maxDist, // only show results within max distance
'orderBy' => 'ISNULL(_distance), _distance', // sort nearest records first -and- unknown or undefined distances last
'limit' => 10
));
}

?>


Hope this helps get you started
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Geolocation Coding Help

Thanks for the quick reply jason.

So when I add this:

$_REQUEST['fromAddress'] = "<?php echo $listingRecord['zipcode'] ?>"; // The ZIP code you want to use goes here

on the front end, I get this error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/illumema/public_html/indulge/index.php on line 53

Re: [Illume Magazine] Geolocation Coding Help

By Jason - June 7, 2011

Hi,

Since this is already in a PHP block, you don't need to use <?php ?>

Try this:

$_REQUEST['fromAddress'] = $listingRecord['zipcode'] ; // The ZIP code you want to use goes here

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Geolocation Coding Help

Hi Jason.

You rock! Awesome. It worked. Many thanks.

Last thing, how do I exclude the current listing from showing up.


See live example: http://indulge.illumemag.com/

Re: [Illume Magazine] Geolocation Coding Help

By Jason - June 8, 2011

Hi,

When you're outputting your records, you can check the "num" of the record you had already selected.

For Example:
<?php
foreach ($myRecords as $record) {

if ($record['num'] == $listingRecord['num']) { continue; }

if (!$record['latitude'] || !$record['longitude']) { continue; }
$jsFunctionArgs = "{$record['latitude']}, {$record['longitude']}, {$record['num']}, '" .escapeJs($record['_link']). "'";
print " _geocoder_addMarker($jsFunctionArgs);\n";
}
?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [zick] Geolocation Coding Help

By Jason - February 8, 2012

Hi Zick,

I think it's just a minor problem in your WHERE clause. Assuming that your field is called Date, you can try this:

'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles) ." AND `Date` > NOW()",

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Geolocation Coding Help

By Mikey - February 8, 2012

Hi Zick,

I think it's just a minor problem in your WHERE clause. Assuming that your field is called Date, you can try this:

'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles) ." AND `Date` > NOW()",

Hope this helps


[:)] Thanks Jason!!!! Works like a charm.