
Can {geodesic:true} be used on GMap.Net? When {geodesic:true} is set on a webbrowser version of GMaps, long distance routes are shown as great circle routes and not straight lines from point A to point B.
Thanks for any help!


Coordinator
Aug 21, 2013 at 1:56 PM

it's possible but you need to calculate the points manually



Hi radioman,
So if I have a line with just 2 points, say where 1 point is in NYC and other is in London, I would have to manually calculate all points in between?


Coordinator
Aug 21, 2013 at 3:08 PM




Gotcha, thanks for the info, radioman.



Got it to work correctly, now also the intersection point is correct :) I used the formulas from here:
http://williams.best.vwh.net/avform.htm#Intermediate
Here's the code, just pass in Start and End points and the number of intermediate points, and you get a List of PointLatLng that form the route along the Great Circle.
/// <summary>
/// Gets a list of Points along a great circle of the earth
/// </summary>
/// <param name="start">The Start point</param>
/// <param name="end">The end point</param>
/// <param name="numPointsBetween">The number of points along the great circle route</param>
/// <returns></returns>
public static List<PointLatLng> GetGreatCircleRoute(PointLatLng start, PointLatLng end, int numPointsBetween)
{
///Check numPointsBetween
if(numPointsBetween <= 1)
{
throw new ArgumentException("numPointsBetween must be larger than 1!");
}
//Create List and add first point:
List<PointLatLng> lstPoints = new List<PointLatLng>(numPointsBetween + 2) { start };
double lat1 = ToRadians(start.Lat);
double lon1 = ToRadians(start.Lng);
double lat2 = ToRadians(end.Lat);
double lon2 = ToRadians(end.Lng);
double d = GetDistanceInRadians(lat1, lon1, lat2, lon2);
double increment = 1d / (double)numPointsBetween;
double f = 0d + increment;
for (int i = 0; i < numPointsBetween; i++)
{
lstPoints.Add(GetGreatCirclePoint(f, d, lat1, lon1, lat2, lon2));
f += increment;
}
//Add last point
lstPoints.Add(end);
return lstPoints;
}
/// <summary>
/// Returns a point that lies on the Great Circle described by Start and End points at a fraction f of distance d
/// </summary>
/// <see cref="http://williams.best.vwh.net/avform.htm#Intermediate"/>
/// <param name="f">Fraction f (0.0 = Startpoint, 1.0 = Endpoint)</param>
/// <param name="d">Distance between Start and Endpoints in RADIANS</param>
/// <param name="lat1">Latitude of Startpoint IN RADIANS</param>
/// <param name="lon1">Longitude of Startpoint IN RADIANS</param>
/// <param name="lat2">Latitude of Endpoint IN RADIANS</param>
/// <param name="lon2">Longitude of Endpoint IN RADIANS</param>
/// <returns>PointlatLng that lies on the great Circle</returns>
public static PointLatLng GetGreatCirclePoint(double f, double d, double lat1, double lon1, double lat2, double lon2)
{
double A = Math.Sin((1d  f) * d) / Math.Sin(d);
double B = Math.Sin(f * d) / Math.Sin(d);
double x = A * Math.Cos(lat1) * Math.Cos(lon1) + B * Math.Cos(lat2) * Math.Cos(lon2);
double y = A * Math.Cos(lat1) * Math.Sin(lon1) + B * Math.Cos(lat2) * Math.Sin(lon2);
double z = A * Math.Sin(lat1) + B * Math.Sin(lat2);
double lat = Math.Atan2(z, Math.Sqrt(x * x + y * y));
double lon = Math.Atan2(y, x);
return new PointLatLng(ToDegrees(lat), ToDegrees(lon));
}
/// <summary>
/// Gets the distance (in RADIANS) between two points specified by latitude/longitude in RADIANS!
/// </summary>
/// <param name="lat1">Latitude of Startpoint IN RADIANS</param>
/// <param name="lon1">Longitude of Startpoint IN RADIANS</param>
/// <param name="lat2">Latitude of Endpoint IN RADIANS</param>
/// <param name="lon2">Longitude of Endpoint IN RADIANS</param>
/// <returns>Distabnce in RADIANS</returns>
public static double GetDistanceInRadians(double lat1, double lon1, double lat2, double lon2)
{
double d = 2d * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin((lat1  lat2) / 2d), 2d) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin((lon1  lon2)/2d), 2d)));
return d;
}



OUTSTANDING WORK, Xandolph! :D Thanks a million!


Aug 26, 2013 at 4:41 PM
Edited Aug 26, 2013 at 4:41 PM

You're welcome :)



Xandolph wrote:
You're welcome :)
Xandolph, if I do a route.Distance output on a route generated by your code, in what format is it being outputted? Miles? Kilometers? Nautical miles?

