Solved

# LATITUDE AND LONGITUDE

Posted on 2014-09-15
197 Views
Hello,

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

Thanks!
0
Question by:SimpleDude
• 3
• 3
• 2

LVL 27

Expert Comment

Latitude is easy.  Longitude is more complicated.

0

LVL 84

Accepted Solution

ozo earned 400 total points
latitude + 0.014457
longitude + 0.014481/cos(latitude)
0

LVL 27

Assisted Solution

d-glitch earned 100 total points
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).
0

Author Comment

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
0

LVL 27

Expert Comment

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?
0

Author Comment

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

LVL 84

Expert Comment

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.
0

Author Closing Comment

Thanks guys
0

## Featured Post

### Suggested Solutions

.NET NamedPipe access using ip address 5 50
DataGridView 2 28
asp.net mvc5 3 35
SQl help with selection 14 43
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…