Re: Script for "Dealer Locator"

From: Nikolai Chuvakhin (nc_at_iname.com)
Date: 07/05/04


Date: 5 Jul 2004 10:59:20 -0700

galsaba@aol.com (Galsaba) wrote in message
   news:<20040704063732.04299.00001036@mb-m15.aol.com>...
>
> I am trying to find a script to a "dealer locator" or "find a store
> near you".
>
> I will have two tables. One will include all US and Canada ZIPs
> including lat and longtitudes. The other one is a table of our
> dealers (or store) including thier ZIP codes.
>
> When the user enters his ZIP code, the application needs to check
> (based on the lat and long) if there is a dealer in a 30 miles
> radious. After the application finds the list of all the dealers
> withing this radius, it will send a list with their name, address,
> and the distance from the (ZIP of ) user.

The formula to find the distancebetween two points given their cordinates
is:

   $distance = $r * acos(cos($lat1) * cos($lon1) * cos($lat2) * cos($lon2) +
                         cos($lat1) * sin($lon1) * cos($lat2) * sin($lon2) +
                         sin($lat1) * sin($lat2));

   where:

   $r -- radius of the Earth
   $lat1 -- latitude of point 1 in radians
   $lon1 -- longitude of point 1 in radians
   $lat2 -- latitude of point 2 in radians
   $lon2 -- longitude of point 2 in radians

You can produce an SQL version of this formula and use it for retrieval
of distances and in the WHERE clause.

Cheers,
NC



Relevant Pages

  • Re: converting spherical coords - 2nd reply
    ... There are minor and major cords, ... Perhaps you want degrees of latitude and longitude. ... AFAIK all common programming languages that cover goniometry follow the pure-mathematics convention of expressing arcs and angles in radians. ...
    (sci.math)
  • Re: Geographic Proximity by Zip Code?
    ... ZIP+4 codes to Census Bureau data, ... Convert miles into latitude and longitude differentials. ... $lon1 -- longitude of point 1 in radians ...
    (alt.php)
  • Re: distance between decimal coordinates
    ... be for a particular distance from another particular decimal ... You need to convert you latitude and longitude to radians and then apply those formulas. ...
    (sci.geo.satellite-nav)
  • Re: GeoClass Advice
    ... I am looking for a geoclass, which initially will return a distance ... $lat1 -- latitude of point 1 in radians ... $lon1 -- longitude of point 1 in radians ...
    (alt.php)
  • Re: Distance formula from Long/Lat Coord
    ... Convert the latitudes and longitudes to radians, ... Let LHA be the difference between the two longitudes, ... Then the sine of the distance angle between the two points, ...
    (microsoft.public.dotnet.languages.vb)