Geoalgorithm for finding coordinates of point from a known location by distance and bearing
Asked Answered
G

5

3

I'd like to use Google maps static API to display a map with a path overlay indicating a boundary.

AFAICT the static API doesn't support polygons, so I intend to circumvent this by drawing the boundary using paths.

To do this I need to determine the points to draw the straight lines (paths) between; so I'd like an algorithm that returns the geographic location (i.e. WGS84 coordinates) a given bearing and distance from a known point.

Can anyone point me to such an algorithm. Preferably in C#, but other languages are acceptable?

Gravimeter answered 29/3, 2009 at 18:10 Comment(1)
It will be radians. Anything working with pi in angles is radians.Posture
G
0

Found this (here: http://williams.best.vwh.net/avform.htm#LL):

A point {lat,lon} is a distance d out on the tc radial from point 1 if:

lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
IF (cos(lat)=0)
    lon=lon1      // endpoint a pole
ELSE
    lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
ENDIF

Will the radial be in radians or degrees?

Edit:

radians = degrees * PI / 180

Gravimeter answered 31/3, 2009 at 16:39 Comment(0)
R
2

I implemented and tested it in C#, using Degrees as input/output instead of radians:

    static readonly double FullCircleDegrees = 360d;
    static readonly double HalfCircleDegrees = FullCircleDegrees / 2d;
    static readonly double DegreesToRadians = Math.PI / HalfCircleDegrees;
    static readonly double RadiansToDegrees = 1 / DegreesToRadians;

    public LatLng GetPointGivenRadialAndDistance(LatLng center, double radius, double azimuth)
    {
        var lat1 = center.Lat * DegreesToRadians;
        var lng1 = center.Lng * DegreesToRadians;
        var lat = Math.Asin( (Math.Sin(lat1) * Math.Cos(radius)) + Math.Cos(lat1) * Math.Sin(radius) * Math.Cos(azimuth * DegreesToRadians));
        var lng = 0d;
        if (Math.Cos(lat) == 0)
        {
            lng = lng1;
        }
        else
        {
            lng = ((lng1 + Math.PI - Math.Asin(Math.Sin(azimuth * DegreesToRadians) * Math.Sin(radius) / Math.Cos(lat1))) % (2 * Math.PI)) - Math.PI;
        }
        return new LatLng(lat * RadiansToDegrees, lng * RadiansToDegrees);
    }
Reiterant answered 19/6, 2009 at 18:49 Comment(1)
It works with 80% accuracy comparing to Great Circle DistanceReiterant
Y
1

You can draw polygon on a KML file, and then show the KML on Google maps.

Here's KML on Google maps (From Google KML Samples) check the "Google Campus - Polygons" section in the content.

Yonina answered 29/3, 2009 at 18:27 Comment(2)
I have very limited experience with KML, but would this work with static maps?Gravimeter
You can pass the KML file as a param of the static map.Yonina
D
1

In (I think) every language I know, radians. Note that I think your example code is giving you co-ordinates based on a sphere, not on WGS84. Here's Java code for converting between co-ordinate systems.

Destructive answered 29/3, 2009 at 18:28 Comment(0)
I
1

Take a look at Gavaghan Geodesy C# library, it should be what you're looking for. And it's free.

Inquisitionist answered 19/6, 2009 at 20:31 Comment(0)
G
0

Found this (here: http://williams.best.vwh.net/avform.htm#LL):

A point {lat,lon} is a distance d out on the tc radial from point 1 if:

lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
IF (cos(lat)=0)
    lon=lon1      // endpoint a pole
ELSE
    lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
ENDIF

Will the radial be in radians or degrees?

Edit:

radians = degrees * PI / 180

Gravimeter answered 31/3, 2009 at 16:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.