Multiple address as separate listings in Geocoder proximity search results

6 posts by 3 authors in: Forums > CMS Builder
Last Post: December 5, 2018   (RSS)

By gkornbluth - November 27, 2018

Hi All,

I find myself lost again trying to use the Geocoder plugin.

I’ve set up a proximity search for a therapy provider directory. I was asked if I could accommodate multiple practice locations (up to 4) for each provider.

I did that by adding 3 additional sets of address fields (practice_street_address2, practice_city2, practice_state2, practice_zip2, practice_street_address3, practice_city3, practice_state3, practice_zip3, etc.) to the account record for that provider's practice and adjusted the user update forms to allow adding that information.

I’d like to be able to include these additional addresses as separate listings in the proximity search results but realized that I don’t have a clue how to do that. My current code is below.

Any thoughts?

Thanks,

Jerry Kornbluth

<?php
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'loadUploads' => true,
'allowSearch' => true,

));

// get geocoding data
list($myLat, $myLng) = geocodeAddress( @$_REQUEST['fromAddress'] );
$kmOrMiles = 'miles'; // can be 'miles' or 'km'
$geoOptions = geocoder_getOptions($myLat, $myLng, @$_REQUEST['maxDistance'], $kmOrMiles);

// get records
list($addressRecords, $addressMetaData) = getRecords(array(
'tableName' => $GLOBALS['GEOCODER_SAMPLE_TABLENAME'],
) + $geoOptions); // geoOptions WILL NOT override the above options

// error checking
$errorsAndAlerts = '';
if (@$_REQUEST['save'])
{
@$count = '';
$action = '' ;
@$count = mb_strlen($_REQUEST['fromAddress'] );
// echo $count ;

if (!@$_REQUEST['fromAddress']) { $errorsAndAlerts .= "No zip/postal code entered<br/>\n"; }
elseif (@$count < 5 ) { $errorsAndAlerts .= "Your zip/postal code must be at least 5 digits long.<br/>\n"; }
elseif (!$myLat || !$myLng) { $errorsAndAlerts .= "Please enter a valid zip/postal code<br/>\n"; }

}

?>
<?php if(@$errorsAndAlerts):?>
<table align="left" width="90%" border="0" cellspacing="0" cellpadding="2">

<tr>
<td align="left" colspan="2"><span class="heading_font" style="color: #C00;"><?php echo @$errorsAndAlerts ?></span></td>
</tr>
</table>
<?php endif ?>

<?php if (!@$_REQUEST['save'] == 1 || @$errorsAndAlerts): // show search form
?>
<table align="left" width="90%" border="0" cellspacing="0" cellpadding="2">


<tr>
<td colspan="2"><span class="heading_font"><b>SEARCH FOR A PROVIDER</b><br />
</span></td></tr>
<?php if(@$errorsAndAlerts):?>
<tr>
<td align="left" colspan="2"><span class="heading_font" style="color: #C00;"><?php echo @$errorsAndAlerts ?></span>
</td>
</tr><?php endif ?>
</table>
<br />
<br />
<!-- Begin Search Form -->
<form method="post" action= "">
<input type="hidden" name="save" value="1" />
<input type="hidden" name="km_miles" value="<?php echo $kmOrMiles ?>" />
<table align="left" width="90%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td valign="top" align="right" class="text_font"><b><font color="#FF0000">*</font> Enter A Zip/Postal Code<br />To Search: <font color="#FF0000">*</font><br />
</b></td>
<td align="left" valign="top" colspan="2"><input type="text" name="fromAddress" value="<?php echo htmlspecialchars(@$_REQUEST['fromAddress']); ?>" size="38" class="text_font" style="background-color:#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>;" placeholder="Please Enter A Zip/Postal Code" id="zip">
<br />

</td>
</tr>
<tr>
<td align="right" class="text_font"><b>Distance?:<br />
</b></td>
<td align="left" valign="top" colspan="2"><select name="maxDistance" width="300" class="text_font" style="width: 300px; max-height: 50px; background-color:#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>;">
<option value="">At Any Distance</option>
<option value="100" <?php selectedIf(100, @$_REQUEST['maxDistance']) ?> >within 100
<?php if ( $kmOrMiles == 'miles'):?>
miles
<?php elseif ( $kmOrMiles == 'km'):?>
km
<?php endif ?>
</option>
<option value="50" <?php selectedIf( 50, @$_REQUEST['maxDistance']) ?> >within 50
<?php if ( $kmOrMiles == 'miles'):?>
miles
<?php elseif ( $kmOrMiles == 'km'):?>
km
<?php endif ?>
</option>
<option value="25" <?php selectedIf( 25, @$_REQUEST['maxDistance']) ?> >within 25
<?php if ( $kmOrMiles == 'miles'):?>
miles
<?php elseif ( $kmOrMiles == 'km'):?>
km
<?php endif ?>
</option>
<option value="10" <?php selectedIf( 10, @$_REQUEST['maxDistance']) ?> >within 10
<?php if ( $kmOrMiles == 'miles'):?>
miles
<?php elseif ( $kmOrMiles == 'km'):?>
km
<?php endif ?>
</option>
<option value="5" <?php selectedIf( 5, @$_REQUEST['maxDistance']) ?> >within 5
<?php if ( $kmOrMiles == 'miles'):?>
miles
<?php elseif ( $kmOrMiles == 'km'):?>
km
<?php endif ?>
</option>
</select></td>
</tr>
<tr>
<td align="right" class="text_font"><b>&nbsp;</b></td>
<td align="left" valign="bottom" colspan="2"><input type="submit" value="Submit Search Filters" ></td>
</tr>
</table> </form>
<!-- End Search Form --> <?php endif ?>

<!-- Begin Results Display -->

<?php foreach ($addressRecords as $record): ?>
<?php if(@$_REQUEST['save']&& !$record['isAdmin'] ):?>
<br />
(
<?php
if (@$record['_distance']) { print number_format($record['_distance'], 1) . " $kmOrMiles away"; }
else { print "unknown distance"; }
?>
) - <a target="_blank" href="http://maps.google.com/?q=<?php echo htmlencode($record['practice_street_address']) ?>, <?php echo htmlencode($record['practice_city']) ?>, <?php echo $record['practice_state'] ?> <?php echo htmlencode($record['practice_zip']) ?>">MAP</a><br />

<b><?php echo htmlencode($record['practice_name']) ?></b> <br/>
<?php echo htmlencode($record['practice_street_address']) ?>
<?php if($record['practice_room_or_floor']):?>
- <?php echo htmlencode($record['practice_room_or_floor']) ?>
<?php endif?>
<br/>
<?php echo htmlencode($record['practice_city']) ?>, <?php echo $record['practice_state'] ?> <?php echo htmlencode($record['practice_zip']) ?>

<?php if($record['practice_street_address_2']):?>
<br />Second Practice Location:<br />
<?php echo htmlencode($record['practice_street_address2']) ?>
<?php if($record['practice_room_or_floor2']):?>
- <?php echo htmlencode($record['practice_room_or_floor2']) ?>
<?php endif?>
<br/>
<?php echo htmlencode($record['practice_city2']) ?>, <?php echo $record['practice_state2'] ?> <?php echo htmlencode($record['practice_zip2']) ?>
<?php endif ?>

<?php if($record['practice_street_address_3']):?>
<br />Third Practice Location:<br />
<?php echo htmlencode($record['practice_street_address3']) ?>
<?php if($record['practice_room_or_floor3']):?>
- <?php echo htmlencode($record['practice_room_or_floor3']) ?>
<?php endif?>
<br/>
<?php echo htmlencode($record['practice_city3']) ?>, <?php echo $record['practice_state3'] ?> <?php echo htmlencode($record['practice_zip3']) ?>
<?php endif ?>

<?php if($record['practice_street_address_4']):?>
<br />Fourth Practice Location:<br />
<?php echo htmlencode($record['practice_street_address4']) ?>
<?php if($record['practice_room_or_floor4']):?>
- <?php echo htmlencode($record['practice_room_or_floor4']) ?>
<?php endif?>
<br/>
<?php echo htmlencode($record['practice_city4']) ?>, <?php echo $record['practice_state4'] ?> <?php echo htmlencode($record['practice_zip4']) ?>
<?php endif ?>
<a href="http://www.dbtproviders.com<?php echo $record['_link'] ?>">Learn More About <?php echo htmlencode($record['practice_name']) ?></a>
<hr align="left" style="height:2px; background-color:#<?php echo $dbt_colorsRecord['menu_background_color'] ?>;" width="90%" color="#<?php echo $dbt_colorsRecord['menu_background_color'] ?>"/>
<?php endif ?>
<?php endforeach ?>
<!-- End Results Display -->
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 Dave - November 28, 2018

Hi Jerry, 

The issue is that geocoder only supports one lat/lng value per record.  So having multiple addresses per record won't work.

What about having the addresses in a separate section and searching on that?  Then you could use a "related records" field under accounts to list all the related addresses?  

Dave Edis - Senior Developer
interactivetools.com

By gkornbluth - November 28, 2018 - edited: November 29, 2018

Hi Dave,

Thanks for looking at this.

That's kind of what I expected. Unfortunate though...

Thanks to Zicky's excellent Related Records examples in post 2241440, I've set up related records for a section called 'additional_practice_locations' with street, city, state, zip, and country information fields, and can populate them in the accounts record editor.

My next hurdles are:

1) To update the form I'm using now, which is based on the Edit Profile form for the website membership plugin, to allow the individual administrators of each multi location practice to use the front end form to enter their additional practice locations.

2) Then I'll need to figure out how to include these additional listings in the Geocoder search results and  multiple address map.

(Or were you suggesting that all addresses, whether the main address or additional locations be entered into the new related records table?)

Any pointers to get me started on the form issue?

Best,

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 29, 2018

c

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 - December 5, 2018

Hi Jerry,

Without being more familiar with the forms you're using it can be difficult to offer general advice on how to proceed and know that it will be helpful. In this case, I would recommend seeing how far you can progress and opening new threads for any specific issues/roadblocks you come across, and then we can continue from there.

Cheers,

Daniel
Technical Lead
interactivetools.com

By gkornbluth - December 5, 2018 - edited: December 5, 2018

Thanks Daniel,

Dave's suggestion to create a separate record for each practice location even though they're under the same corporate umbrella, so as to order to satisfy the geocoder plugin's requirements, has caused me to change direction somewhat anyway, so I'll pursue the new challenges in new threads.

I would have liked to have all of the practice location addresses in a single table, but that seems to be unwieldy given the geocoder's restrictions.

Best,

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