Posted on 2014-09-15
Last Modified: 2014-09-15

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

Question by:SimpleDude
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
LVL 27

Expert Comment

ID: 40323401
Latitude is easy.  Longitude is more complicated.
LVL 84

Accepted Solution

ozo earned 400 total points
ID: 40323405
latitude + 0.014457
longitude + 0.014481/cos(latitude)
LVL 27

Assisted Solution

d-glitch earned 100 total points
ID: 40323417
And you need to be careful at the boundaries:  the N and S poles, the equator, the prime (0 deg) meridian and its opposite (180 deg).
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.


Author Comment

ID: 40323426
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
LVL 27

Expert Comment

ID: 40323453
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?

Author Comment

ID: 40323466
Something like that. The point of origin (lat-long) changes constantly, that's why I cannot calculate it just once.
LVL 84

Expert Comment

ID: 40323474
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.

Author Closing Comment

ID: 40323557
Thanks guys

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Win a Jar of Candy Corn: A Scientific Approach! I love mathematics. If you love mathematics also, you may enjoy this tip on how to use math to win your own jar of candy corn and to impress your friends. As I said, I love math, but I gu…
We are taking giant steps in technological advances in the field of wireless telephony. At just 10 years since the advent of smartphones, it is crucial to examine the benefits and disadvantages that have been report to us.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question