Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>first of all use a map and ask the user to set his approximate location, get that values, with this code get the distance to each store:</p> <p>google.maps.geometry.spherical.computeDistanceBetween (latLngA, latLngB);</p> <p>from <a href="https://developers.google.com/maps/documentation/javascript/reference?hl=en-US#spherical" rel="nofollow noreferrer">https://developers.google.com/maps/documentation/javascript/reference?hl=en-US#spherical</a></p> <p>now choose the shorter and output it</p> <p>but I'd rather ask him to input the City and get the distance through Wolfram api request</p> <pre><code> $city=customer_city; $north=store_north; //coordinate_l $west=store_west; //coordinate_L $wolfram_query="http://api.wolframalpha.com/v2/query?appid=".$appid."&amp;input=distance%20from%20".$city."%20to%20".$north."N%20".$west."W%20in%20km&amp;format=image,plaintext"; </code></pre> <p>and get the distance from the xml answer leaving google maps out</p> <p>an other option using zipcodes is to calculate the spherical distance from two coordinates with this php function inside a while loop going through all the lat and long of the sores:</p> <pre><code>function calcDist($lat_A, $long_A, $lat_store[i], $long_store[i]) { $distance = sin(deg2rad($lat_A)) * sin(deg2rad($lat_B)) + cos(deg2rad($lat_A)) * cos(deg2rad($lat_B)) * cos(deg2rad($long_A - $long_B)); $distance = (rad2deg(acos($distance))) * 69.09; return $distance; } </code></pre> <p>distance is in miles, if you want the distance in km use this</p> <pre><code> function miles2kms($miles) { $ratio = 1.609344; $kms = $miles * $ratio; return $kms; } </code></pre> <p>and you can retrieve the lat and long of the zip code using this database: <a href="http://sourceforge.net/projects/zips/files/#files" rel="nofollow noreferrer">http://sourceforge.net/projects/zips/files/#files</a> or this <a href="http://postcodedb.sourceforge.net/dumpCSV.php" rel="nofollow noreferrer">http://postcodedb.sourceforge.net/dumpCSV.php</a></p> <p>to improve the result of the distance you should use Haversine or Vincenty calculations... which are a little more complex..</p> <p>... but what we like of the net is that someone has surely done this before we did, and of course shared his efforts! <a href="http://www.phpclasses.org/package/6480-PHP-Calculate-the-distance-between-Earth-two-points.html" rel="nofollow noreferrer">http://www.phpclasses.org/package/6480-PHP-Calculate-the-distance-between-Earth-two-points.html</a> this is a class that implements haversine distance! this might be better... if you want to use Vincenty try this: <a href="https://stackoverflow.com/questions/11416767/implementing-vincentys-formula-in-php">Implementing Vincenty&#39;s Formula in PHP</a> , try which one gives you the best results, even if the most accurate will always be wolfram, mathematicians worked on that, so that works pretty well ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload