29

using a Latitude and Longitude value (Point A), I am trying to calculate another Point B, X meters away bearing 0 radians from point A. Then display the point B Latitude and Longitude values.

Example (Pseudo code):

PointA_Lat = x.xxxx;
PointA_Lng = x.xxxx;
Distance = 3; //Meters
bearing = 0; //radians

new_PointB = PointA-Distance;

I was able to calculate the distance between two Points but what I want to find is the second point knowing the distance and bearing.

Preferably in PHP or Javascript.

Thank you

pawelglow
  • 708
  • 1
  • 10
  • 20

4 Answers4

49

It seems you are measuring distance (R) in meters, and bearing (theta) counterclockwise from due east. And for your purposes (hundereds of meters), plane geometry should be accurate enough. In that case,

dx = R*cos(theta) ; theta measured counterclockwise from due east
dy = R*sin(theta) ; dx, dy same units as R

If theta is measured clockwise from due north (for example, compass bearings), the calculation for dx and dy is slightly different:

dx = R*sin(theta)  ; theta measured clockwise from due north
dy = R*cos(theta)  ; dx, dy same units as R

In either case, the change in degrees longitude and latitude is:

delta_longitude = dx/(111320*cos(latitude))  ; dx, dy in meters
delta_latitude = dy/110540                   ; result in degrees long/lat

The difference between the constants 110540 and 111320 is due to the earth's oblateness (polar and equatorial circumferences are different).

Here's a worked example, using the parameters from a later question of yours:

Given a start location at longitude -87.62788 degrees, latitude 41.88592 degrees, find the coordinates of the point 500 meters northwest from the start location.

If we're measuring angles counterclockwise from due east, "northwest" corresponds to theta=135 degrees. R is 500 meters.

dx = R*cos(theta) 
   = 500 * cos(135 deg) 
   = -353.55 meters

dy = R*sin(theta) 
   = 500 * sin(135 deg) 
   = +353.55 meters

delta_longitude = dx/(111320*cos(latitude)) 
                = -353.55/(111320*cos(41.88592 deg))
                = -.004266 deg (approx -15.36 arcsec)

delta_latitude = dy/110540
               = 353.55/110540
               =  .003198 deg (approx 11.51 arcsec)

Final longitude = start_longitude + delta_longitude
                = -87.62788 - .004266
                = -87.632146

Final latitude = start_latitude + delta_latitude
               = 41.88592 + .003198
               = 41.889118
Jim Lewis
  • 43,505
  • 7
  • 82
  • 96
  • Thank you Jim for the edit example! I really appreciate it. I fully understand the concept now. – pawelglow Feb 18 '10 at 04:06
  • Jimk Lewis: I tried using your formula here (http://stackoverflow.com/questions/8064930/google-maps-v3-circle-circle-that-i-created-do-not-match) and did not get a perfect circle, please have a look! – Nyxynyx Nov 09 '11 at 12:22
  • Hmm, does this work anywhere on the globe? Seems to only work in some locations. I'm trying to plot a point southeast, and sometimes I end up northwest instead. – paulwhit Apr 27 '12 at 19:34
  • @paulwhit: This is an approximation, which should work well for the OP's situation (distances on the order of meters). The approximation breaks down if the starting point is close to the north or south pole, or if the distance is too large. So, for an extreme example, if you're 1 meter away from the north pole at longitude 0 degrees, and walk 100 meters due east (several laps around the pole...) this formula won't give the correct final coordinates. If your results are falling into the wrong quadrant for other scenarios, make sure you're using the right convention for measuring theta. – Jim Lewis Apr 27 '12 at 21:04
  • @paulwhit: One also needs to be careful about the longitude convention -- locations west of the prime meridian might be expressed as "longitude 75 degrees W", but this should be represented as -75 degrees, so the trigonometry works out properly. – Jim Lewis Apr 27 '12 at 22:02
  • I have tested this formula and didn't worked. The best Idea is using UTM and adding/subtacting offset. – Gödel77 Nov 18 '14 at 15:09
  • Here (http://stackoverflow.com/questions/30002372/given-point-of-latitude-longitude-distance-and-bearing-how-to-get-the-new-la) is another formula, it's a little different from yours. which is better? – gfan May 03 '15 at 00:02
  • 4
    110540 and 111320, where do these numbers come from? – gfan May 03 '15 at 05:02
  • 2
    @gfan: One degree of latitude on the Earth's surface equals 110540 meters. One degree of longitude equals 111320 meters (at the equator). They're different because the Earth isn't a perfect sphere. It bulges out at the equator, so the equatorial circumference is slightly larger than the polar circumference. – Jim Lewis May 03 '15 at 17:37
  • pay attention to units; bearing/lat/lon is in degrees - I use np.sin/cos which are in radians - units must be converted to same, and then it works fine – Dimitris Sep 20 '17 at 13:41
3

It might help if you knew that 3600 seconds of arc is 1 degree (lat. or long.), that there are 1852 meters in a nautical mile, and a nautical mile is 1 second of arc. Of course you're depending on the distances being relatively short, otherwise you'd have to use spherical trigonometry.

Arthur Kalliokoski
  • 1,627
  • 12
  • 12
  • 1
    Spherical trig is a good point to raise. If the distances are anything larger than a few miles they will diverge from the globe and be up in the air. If this matters or not depends on your use-case, precision and goals. Perhaps he's not working on a globe but some flat space. – Karl Feb 02 '10 at 21:22
  • Karl and akallio, thanks for the input. Im actually working on a flat surface and the distance will be about 500 meters. – pawelglow Feb 02 '10 at 21:29
  • so just to confirm using the conversion above: 500meters = 0.2699784 sec of arc? – pawelglow Feb 02 '10 at 21:45
  • @akallio: A nautical mile is one arcmin, not arcsec. And that is only true along a great circle -- one nautical mile east or west does not correspond to 1/60 degree of longitude except at the equator. – Jim Lewis Feb 02 '10 at 23:14
2

Here is an updated version using Swift:

let location = CLLocation(latitude: 41.88592 as CLLocationDegrees, longitude: -87.62788 as CLLocationDegrees)

let distanceInMeter : Int = 500
let directionInDegrees : Int = 135

let lat = location.coordinate.latitude
let long = location.coordinate.longitude

let radDirection : CGFloat = Double(directionInDegrees).degreesToRadians

let dx = Double(distanceInMeter) * cos(Double(radDirection)) 
let dy = Double(distanceInMeter) * sin(Double(radDirection))

let radLat : CGFloat = Double(lat).degreesToRadians

let deltaLongitude = dx/(111320 * Double(cos(radLat)))  
let deltaLatitude = dy/110540                   

let endLat = lat + deltaLatitude
let endLong = long + deltaLongitude

Using this extension:

extension Double {
    var degreesToRadians : CGFloat {
        return CGFloat(self) * CGFloat(M_PI) / 180.0
    }
}
SteffenK
  • 582
  • 6
  • 17
-2

dx = sin(bearing)
dy = cos(bearing)
x = center.x + distdx;
y = center.y + dist
dy;

Chris H
  • 6,433
  • 5
  • 33
  • 51
  • centerX=41.88592 (Latitude) and centerY=-87.62788 (Longitude) My distance is 500meters. The above calculation does not give me the coordinates 500meters right of my original location. The distance is in the wrong format so im trying to figure that out next. – pawelglow Feb 02 '10 at 21:41
  • true, it depends on the convention for the bearing. if 0 is "to the right" and x+ is "to the right" then swap sin and cos... the convention wasn't given in the question so I made something up at random. – Chris H Feb 02 '10 at 23:17
  • dx = cos(0) = 1, dy = sin(0) = 0, x = 41 + 500*1, y = -87 + 500*0 – Chris H Feb 02 '10 at 23:18
  • If you want to express dx and dy in degrees longitude and latitude, there's a cos(latitude) correction factor involved. – Jim Lewis Feb 02 '10 at 23:48