Limit a Geocoder multi pin map to a radius from a visitor entered Zip/Postal code

By gkornbluth - November 8, 2018

Hi All,

This is my first time dealing with the Geocoder's sample_map_multi.php example to make a multi pinned map and I’ve got it looking pretty good on the site I’m working on. http://dbtproviders.com/map_multi.php

I’d like to be able to limit what the map shows to a distance from a visitor entered zip/postal code and although I see, and have used, the code in the sample_search.php example, and have seen some code snippets on-line, I have no idea how I’d combine the lot to accomplish the limiting.

Any help appreciated.

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - November 14, 2018

Thanks for the thorough response Daniel,

I'll implement this first thing in the morning.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - November 15, 2018

Hi Daniel,

Got everything working as it should and added some MySQL where arguments to exclude admin and junior admin records from being included in the map.

I’m still stuck on one issue, and that is excluding records that have not been updated in 6 months from being included in the search results.

I’ve been doing this successfully as part of a foreach loop with if statements but can’t figure out how to translate the concept to MySQL

Here’s what I’m up to in the MySQL at the moment:

// get records
list($myRecords, $myMetaData) = getRecords(array(
'tableName' => $GLOBALS['GEOCODER_SAMPLE_TABLENAME'],
'where' => " (isAdmin = '0' OR isAdmin = '') AND (notAdmin = '0' OR notAdmin = '')",


) + $geoOptions); // geoOptions WILL NOT override the above options

And here’s how I’ve been handling the exclusions in the foreach situation.

<?php foreach ($myRecords as $record): ?>
<?php
$updateUnixTime = strtotime( $record['updatedDate'] ); // seconds since 1970
$sixMonths = time() - (180*60*60*24) ;
$sixMonthsGone = $updateUnixTime > $sixMonths;

?>
<?php if(@$_REQUEST['save'] && !$record['isAdmin'] == ‘1' && !$record['notAdmin'] == '1' && ( $sixMonthsGone) ):?>
<br />
Display the valid record information here.

<?php endif ?>

<?php endforeach ?>

I know it's asking a lot, but could you offer some of your expert guidance on this?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - November 15, 2018

Hey Jerry,

It sounds like you're asking how to exclude the older records within the WHERE clause, rather than skipping them with PHP? If that's the case, you can do so relatively easily, as you can use comparison operators on datetime values in MySQL so long as it's the right format ("yyyy-mm-dd hh:mm:ss"). This format can be produced in PHP with the date() function format "Y-m-t H:i:s".

Also, a helpful tidbit is that strtotime() can use relative date formats (http://php.net/manual/en/datetime.formats.relative.php), so you can use things like strtotime( "6 months ago" ); to save yourself some math.

Putting that all together will give you something like this:

$sixMonthsAgo = strtotime( '6 months ago' );

// get records
list($myRecords, $myMetaData) = getRecords(array(
  'tableName' => $GLOBALS['GEOCODER_SAMPLE_TABLENAME'],
  'where' => " (isAdmin = '0' OR isAdmin = '') AND (notAdmin = '0' OR notAdmin = '') AND updatedDate > '" . date('Y-m-t H:i:s', $sixMonthsAgo) . "'", 
) + $geoOptions); // geoOptions WILL NOT override the above options

Hope that helps!

Cheers,

Daniel
Technical Lead
interactivetools.com

By gkornbluth - November 15, 2018

Wow! Thanks Daniel,

So this will look at all the records updatedDate field and if the date is more than 6 months old not include that record in the list?

Seems really easy (when you know what you're doing!)...

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - November 15, 2018

Hey Jerry,

I'd make sure to do some thorough testing to make sure that it's limiting the records appropriately, but yes that's the idea!

Glad to help.

Daniel
Technical Lead
interactivetools.com