Link to home
Start Free TrialLog in
Avatar of SimpleDude
SimpleDude

asked on

LATITUDE AND LONGITUDE

Hello,

How do I add, and substract 1 mile for a given latitude? And 1 mile to a given longitude?

Thanks!
Avatar of d-glitch
d-glitch
Flag of United States of America image

Latitude is easy.  Longitude is more complicated.

    http://www.answers.com/Q/How_many_miles_are_in_a_degree_of_longitude_or_latitude
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SimpleDude
SimpleDude

ASKER

Hi guys, I just need to select X number of records within a Lat and Long range.

I was using this formula, but it drastically decreases the server performance:

  (ACOS(SIN(47.988594 * PI() / 180) * SIN(dbo.ADDRESSES.latitude * PI() / 180) + COS(47.988594 * PI() / 180) * COS(dbo.ADDRESSES.latitude * PI()
                      / 180) * COS((- 122.201789 - dbo.ADDRESSES.longitude) * PI() / 180)) * 180 / PI() * 60 * 1.1515 BETWEEN 0 AND @distance
How big is the data base?  Is it sorted in any way?
What units are used in the database?  Degrees or radians?
You should search in the same units the data base uses.  Save a lot on conversions.

This   (SIN(47.988594 * PI() / 180)  (and several similar terms) are constants.  
You only have to calculate them once.

Is this related to the nearest k restaurants problem?
Something like that. The point of origin (lat-long) changes constantly, that's why I cannot calculate it just once.
If the restaurants are in a small area, it may be preferable to convert the latitudes and longitudes into a flat grid to make distance calculations easier.
If the restaurants are in a large area where a flat approximation would be inaccurate, it may be preferable to convert into a 3-d orthogonal coordinate system to make distance calculations easier.
Thanks guys