开发者

Calculate GPS coordinates to form a radius of given size

I've come up with a method that takes a coordinate and a range (in miles) and return a list of coordinates that form a circle around the origin. I seem to have made some progress with it, but I have an issue with getting the range part down.

private const Double LAT_MILE = 0.0144839;
private const Double LONG_MILE = 0.0190693;

public static List<Gps.Coordinate> GetRadius(Double OriginLatitude, Double OriginLongitude, Double Range, int Points)
{
    List<Gps.Coordinate> Result = new List<Coordinate>();

    //insert a new point
    for (int i = 0; i < Points; i++)
    {
        Result.Add(new Gps.Coordinate()
        {
            Latitude = ((Range * LAT_MILE) * System.Math.Cos(i)) + OriginLatitude,
            Longi开发者_运维技巧tude = ((Range * LONG_MILE) * System.Math.Sin(i)) + OriginLongitude
        });
    }

    //sort using nearest neighbor
    return SortCoords(ref Result);
}

The issue I've found is that the constant I'm using to tell the distance in miles to degrees changes depending on location.. Does anyone have any suggestions for resolving this issue, or a better mousetrap altogether?

EDIT: I should note, I'm horrible at math :)


have a look at this (includes example code): http://www.movable-type.co.uk/scripts/latlong.html

the "Spherical Law of Cosines" gives you the distance between two coordinates. it should be possible to modify this to give you the coordinates around a specified center and a specified radius (distance).


Rather than defining LONG_MILE as a constant, you should calculate it inside your GetRadius function: LONG_MILE = LAT_MILE / cos(OriginLatitude*PI/180.0)

Also, it looks a little weird that you're taking sin() and cos() of your integer index i. If your intention is to generate points at 1 radian intervals surrounding the center point, it'll work. But I suspect you might want something more like

angle_radians = i * 2.0*PI/Points; 

and substitute sin(angle_radians) for sin(i), etc.


Do your calculations in a spherical coordinate space and then convert them to latitude/longitude.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜