tags:

views:

560

answers:

3

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,
            Longitude = ((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 :)

+3  A: 

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).

stmax
+1  A: 

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.

Jim Lewis
A: 

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

Loren Pechtel