Search By Radius, Technical Details

Why Search By Radius?

The design of the search is based on the premise that most people that are searching for something don’t care what state (where) your store is located.  They only care that it is 3 miles away not 30 miles away.

I understand this is not a perfect solution for everyone.  Sometimes you need to refer someone to the proper sales agent based on sales territories which are typically based on state/city/country.    Discrete search  can help with that, however territory support is not part of the basic Search  add-on unless your territories are divided by city, state, or country alone. Directory Builder add-on can be used for territory search of that nature if no Map is included.  Territories is now included in the Premier Add-on

Technical Details

The search algorithm converts the latitude and longitude of the starting search address and each store by using a spherical cosine formula.   The short version of this is that the latitude and longitude are subtracted from each other and multiplied by 6371 kilometers or 3959 miles.  This is the radius of the earth and is used to determine how far apart two points are on a perfect sphere.

As you know, the Earth is not a perfect sphere and thus this formula is an approximation.  The closer your points are to one of the poles, the more varied the terrain, and other factors will dictate how accurate the results are.   However, in most cases this is the accepted methodology and formula for finding the distance between two points when given the latitude and longitude on Earth.

Looking Under The Covers

I often get email asking why the search is broken.  Sometimes I get a URL showing the problem.   The fastest way for me to see what is going on is if you use the web browser developer tools and report any error messages.   These are built into IE and Chrome.  For Firefox I use the Firebug add-on.   All 3 will show all the JavaScript and AJAX trickery.  I’ve even buried some helpful data in the JSON response coming back from the server when you perform a search so I can see what is happening without being intrusive.

Here is what a state search looks like.  You can see that the CA selection puts the marker just outside Fresno.  If you look in the JavaScript debugger (this one is Chrome Dev Tools) you can see the form data that was sent behind the scenes.   It is searching for locations within 50 miles of the address “CA”.  The address CA has a lat of 36.778261 and a long of -119.417932.

Search Query
Search Query

Here is the response where you can see the SQL query used in the location database, the version of SLP, and the results.  Here the count of 0 shows now results.  If you click the response tab you can see the list of locations (there are none).

Search Response
Search Response