# Converting miles to degrees longitude or latitude

Someone sent me email regarding my online calculator for computing the distance between to locations given their longitude and latitude values. He wants to do sort of the opposite. Starting with the longitude and latitude of one location, he wants to find the longitude and latitude of locations moving north/south or east/west of that location. I like to answer reader questions when I can, so here goes. I’ll give a theoretical derivation followed by some Python code.

Longitude and latitude and are usually measured in degrees, but theoretical calculations are cleaner in radians.  Someone using the Python code below could think in terms of degrees; radians will only be used inside function implementations. We’ll use the fact that on a circle of radius r, an arc of angle θ radians has length rθ. We’ll assume the earth is a perfect sphere. See this post for a discussion of how close the earth is to being a sphere.

## Moving North/South

I’ll start with moving north/south since that’s simpler. Let R be the radius of the earth. An arc of angle φ radians on the surface of the earth has length M = Rφ, so an arc M miles long corresponds to an angle of φ = M/R radians. Moving due north or due south does not change longitude.

## Moving East/West

Moving east/west is a little more complicated. At the equator, the calculation is just like the calculation above, except that longitude changes rather than latitude. But the distance corresponding to one degree of longitude changes with latitude. For example, one degree of longitude along the Arctic Circle doesn’t take you nearly as far as it does at the equator.

Suppose you’re at latitude φ degrees north of the equator. The circumference of a circle at constant latitude φ, a circle parallel to the equator, is cos φ times smaller than the circumference of the equator. So at latitude φ an angle of θ radians describes an arc of length M = R θ cos φ. A distance M miles east or west corresponds to a change in longitude of θ = M/(R cos φ). Moving due east or due west does not change latitude.

## Python code

The derivation above works with angles in radians. Python’s cosine function also works in radians. But longitude and latitude are usually expressed in degrees, so function inputs and outputs are in degrees.

```import math

# Distances are measured in miles.
# Longitudes and latitudes are measured in degrees.
# Earth is assumed to be perfectly spherical.

def change_in_latitude(miles):
"Given a distance north, return the change in latitude."

def change_in_longitude(latitude, miles):
"Given a latitude and a distance west, return the change in longitude."
# Find the radius of a circle around the earth at given latitude.

## 13 thoughts on “Converting miles to degrees longitude or latitude”

1. You may find math.radians() and math.degrees() useful.

2. Thanks. I hadn’t noticed those functions.

3. kameran

dr. cook i still need help on my math im in the 6th grade and i dont get this stuff … plz email me and tell me how in the world does this stuff work thnks so so much i really need ur help
kameran!!!!

4. Kameran, Are you wanting to understand longitude and latitude? You can send me email to discuss you questions. My email address and other contact info is listed here.

5. Suresh

John,
Can you help me converting ***ft North , ****East into degress format ( I mean ** deg.N, ***Deg.E)

6. Tomas Bar

Hi,
Thanks for such a clear explanation and useful script.
Do you know how the script could be tweaked in order to get lat/long in some not completely spherical projection system- like WGS84 (1984 datum)?
Thanks very much.
tomas bar

7. Tomas, sorry, but I’m not familiar with that.

8. Thanks for the great explanation and code!

9. Thanks for the great explanation. I am referencing this blog and giving you credit in a blog I just finished: over here

10. Check Again

Your formula works only when travelling in the cardinal directions. In any other direction whether you travel N-S 1st and E-W 2nd or the other way around, you will get different points of longitude, even over very small distances near the equator. When you approach the poles your error (in deg will grow significantly).

To reduce the error (not eliminate it), one can use the radius of longitude at the median latitude.

11. Check Again

Your formula works only when travelling in the cardinal directions. In any other direction whether you travel N-S 1st and E-W 2nd or the other way around, you will get different points of longitude, even over very small distances near the equator. When you approach the poles your error (in deg will grow significantly).

To reduce the error (not eliminate it), one can use the radius of longitude at the median latitude.