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. earth_radius = 3960.0 degrees_to_radians = math.pi/180.0 radians_to_degrees = 180.0/math.pi def change_in_latitude(miles): "Given a distance north, return the change in latitude." return (miles/earth_radius)*radians_to_degrees 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. r = earth_radius*math.cos(latitude*degrees_to_radians) return (miles/r)*radians_to_degrees

**Related posts**:

What is the shape of the earth?

Spherical trigonometry

Finding distances using latitude and longitude

I recently had a similar question, and found some great functions at http://www.movable-type.co.uk/scripts/latlong.html

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

Thanks. I hadn’t noticed those functions.

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!!!!

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.

John,

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

Thanks for your help

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

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

Thanks for the great explanation and code!

I’ve linked this from stackoverflow.com “Convet long/lat to pixel x/y on a given picure.” – maybe this article helps:

http://stackoverflow.com/questions/2651099/convet-long-lat-to-pixel-x-y-on-a-given-picure/2651276#2651276

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

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.

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.