Proximity Search results for Germany not working
13 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 6, 2016 (RSS)
By gkornbluth - May 21, 2016 - edited: May 22, 2016
Hi All,
My implementation of Geocoder is working almost perfectly, except for the proximity search function. (CMSB V3.04, Geocoder 1.04)
My client wants to be able to include locations outside the US and Canada, so I entered a test address in Germany (Friedrichstr. 140, 10117 Berlin).
I’m using the provided sample_search.php page with an map link added for each search result, and the map shown is indeed of Berlin.
However, when I enter the New York Zip code 10019, the search includes the Berlin result as if the 2 addresses are only about a mile apart (They’re actually almost 4000 miles apart).
The search page code is below (with the field names changed to match my site, and the map link added).
I hope someone has a thought on how to fix the problem.
You can see the result at: http://www.dbtproviders.com/sample_search.php
Thanks,
Jerry Kornbluth
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home3/ellescho/public_html/dbtproviders/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// error checking
if (!@$GLOBALS['GEOCODER_PLUGIN']) { die("You must activate the Geocoder plugin before you can access this page."); }
// set default values (not required)
if (!array_key_exists('fromAddress', $_REQUEST)) { $_REQUEST['fromAddress'] = '10001'; } // this is the default address/postalcode if none entered
// 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['search']) {
if (!@$_REQUEST['fromAddress']) { $errorsAndAlerts .= "No address entered!<br/>\n"; }
elseif (!$myLat || !$myLng) { $errorsAndAlerts .= "We couldn't determine your location, please try again!<br/>\n"; }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Proximity search with results sorted by distance</title>
<style type="text/css">
body, td { font-family: arial; font-size: 14px; }
</style>
</head>
<body>
<h1>Proximity search with results sorted by distance</h1>
<?php if (@$errorsAndAlerts): ?>
<div style="color: #C00; font-weight: bold; font-size: 12px; font-family: arial;">
<?php echo $errorsAndAlerts; ?><br/>
</div>
<?php endif ?>
Enter your address or postal code to see nearby results:<br/>
<form method="post" action="?">
<input type="hidden" name="search" value="1" />
<input type="text" name="fromAddress" value="<?php echo htmlspecialchars(@$_REQUEST['fromAddress']); ?>" size="30" />
<select name="maxDistance">
<option value="">at any distance</option>
<option value="100" <?php selectedIf(100, @$_REQUEST['maxDistance']) ?> >within 100 miles</option>
<option value="50" <?php selectedIf( 50, @$_REQUEST['maxDistance']) ?> >within 50 miles</option>
<option value="25" <?php selectedIf( 25, @$_REQUEST['maxDistance']) ?> >within 25 miles</option>
<option value="10" <?php selectedIf( 10, @$_REQUEST['maxDistance']) ?> >within 10 miles</option>
<option value="5" <?php selectedIf( 5, @$_REQUEST['maxDistance']) ?> >within 5 miles</option>
</select>
<input type="submit" value="Search" />
</form>
<?php if (@$_REQUEST['search'] && !$errorsAndAlerts): ?>
<ul style="line-height: 1.5">
<?php foreach ($addressRecords as $record): ?>
<li>
<?php echo htmlspecialchars($record['practice_name']); ?>,
<?php echo htmlspecialchars($record['practice_street_address']); ?>,
<?php echo htmlspecialchars($record['practice_city']); ?>,
<?php echo htmlspecialchars($record['practice_state']); ?>
<?php echo htmlspecialchars($record['practice_zip']); ?>,
<?php echo htmlspecialchars($record['practice_country:label']); ?>
(<?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']) ?> <?php echo htmlspecialchars($record['practice_country:label']); ?>"> CLICK/TAP FOR A MAP</a>
</li>
<?php endforeach ?>
<?php if (!$addressRecords): ?>
<li>No results found!</li>
<?php endif ?>
</ul>
<?php endif ?>
</body>
</html>
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By Damon - May 23, 2016
Hi Jerry,
I was able to recreate the issue and found the solution. What was happening was the Zipcode from Germany was getting treated like a US zip code and was geocoding based on that.
The solution is the open up your geocoder.php plugin file.
Go to line 32 and comment out this line like this:
//'postcode/zipcode/zip/address',
You will need to re-geocode the address from Germany (delete the Latitude and Longitude values and save).
Let me know if this works for you.
Thanks!
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By gkornbluth - May 31, 2016
Thanks Damon,
I didn't get an email telling me that this thread had been updated, sorry for the delay in responding.
I'll give it a try tomorrow morning and report back.
Best,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By gkornbluth - May 31, 2016
Hi Damon,
Works like a charm...
Thanks again!
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By gkornbluth - May 31, 2016
Hi Damon,
There's still one thing about all this that still confuses me.
I can enter a Canadian or a US Postal Code and the proximity results come out correctly.
How would I enter a German Postal Code (or any other Country's code that has the same format as the US or Canadian codes) and have the proximity results come out correctly?
Thanks again,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By Damon - June 2, 2016
Hi Jerry,
Google's Geocoding API typically does a good job of guessing what region you want results from when there are ambiguities in the search.
So being in North America, if we just enter a postal code, it returns results for the US or Canada, etc. The example German postal code (10117), matches a US postal code so the US location us returned.
To get the German location, more than just the postal code will need to be entered. Adding instructions for users to enter the full address should hopefully solve the issue.
Does this work for you? Let me know if you have any other questions about this.
Thanks!
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By gkornbluth - June 3, 2016
Hi Damon,
Again no email about your updated post. I unsubscribed and then resubscribed to this thread so we'll see if that helps... (so please reply to this)
About the Geocoding issue:
Seems like it might be possible to enter the postal code and just the country of interest and get the correct results.
I'll do some testing and post my findings.
Thanks for pointing me in the right direction.
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By Damon - June 3, 2016
Hi Jerry,
I checked the Outgoing Mail logs and the last forum notification email was sent you on 2016-06-02 at 12:25:37 PM.
Maybe that will help track it down?
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By Damon - June 3, 2016
I also subscribed to this thread with my personal email and just received the forum post update so emails are being sent.
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By gkornbluth - June 3, 2016
Hi Damon,
Think I may have discovered the email problem.
Could I trouble you to reply to this post?
Thanks,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php