1

I want to find the GeoCoordinate of the place that is 4000km right to my position, name it newLocation.

I need that in order to convert the result into ViewportPoint like this:

System.Windows.Point p1 =
mapControl.ConvertGeoCoordinateToViewportPoint(newLocation);

and assuming my location is defined as:

System.Windows.Point p2 =
radiusMap.ConvertGeoCoordinateToViewportPoint(myLocation);

then I can simply add a circle centered on my location, and the border passes from newLocation that I need to calculate, like this:

    double radius = getDistance(p1, p2);

    Ellipse circle = new Ellipse();
    circle.Width = radius * 2;
    circle.Height = radius * 2;
    circle.Opacity = 0.4;
    circle.Fill = new SolidColorBrush(Colors.Green);
    MapOverlay mapOverLay = new MapOverlay();
    mapOverLay.PositionOrigin = new System.Windows.Point(0.5, 0.5);
    mapOverLay.Content = circle;
    mapOverLay.GeoCoordinate = myLocation;
    MyLayer.Add(mapOverLay);

    radiusMap.Layers.Add(MyLayer);

So, calculating newLocation is all what I need.

Notes:

  1. I tried this solution but there is a limitation.
  2. We can do the following in visual studio:

    GeoCoordinate location1 = ..., location2 = ...;
    double distance = location1.GetDistanceTo(location2);
    

I wonder if the inverse is already implemented.

UPDATE: I found the implementation of GetDistanceTo(...) and here it is:

double d = this.Latitude * 0.017453292519943295;
double num3 = this.Longitude * 0.017453292519943295;
double num4 = other.Latitude * 0.017453292519943295;
double num5 = other.Longitude * 0.017453292519943295;
double num6 = num5 - num3;
double num7 = num4 - d;
double num8 = Math.Pow(Math.Sin(num7 / 2.0), 2.0) + ((Math.Cos(d) * Math.Cos(num4)) * Math.Pow(Math.Sin(num6 / 2.0), 2.0));
double num9 = 2.0 * Math.Atan2(Math.Sqrt(num8), Math.Sqrt(1.0 - num8));
return (6376500.0 * num9);

I wonder if getting the inverse is possible or not. i.e. giving it the geocoordinates of me, and the distance from me, so that it returns the geocoordinates of the new location.

Community
  • 1
  • 1
Hamzeh Soboh
  • 7,572
  • 5
  • 43
  • 54

1 Answers1

2

There are of course an infinite number of points (around a circle) which are 400km from an initial starting point, you will need to define both the distance and the bearing in order to reduce this to a single point.

If you can assume the Earth to be a sphere, you can travel around a great circle as shown

φ2 = asin( sin(φ1)*cos(d/R) + cos(φ1)*sin(d/R)*cos(θ) )
λ2 = λ1 + atan2( sin(θ)*sin(d/R)*cos(φ1), cos(d/R)−sin(φ1)*sin(φ2) )

where

  • φ is latitude
  • λ is longitude
  • θ is the bearing (in radians, clockwise from north)
  • d is the distance traveled
  • R is the earth’s radius 6 378.1 kilometers
  • d/R is the angular distance, in radians

So plug in your values to calculate the new location φ2, λ2

If by "right to my position" you mean due East, θ will be 90 degrees = Π / 2

Of course there is a hack you could use to find a point due East. One degree of longitude at the Equator = 110.57 km . Hence you could calculate an upper bound and then interate down to a reasonable threshold.

  1. Take your start point - for 400km, add 3.61 degrees.
  2. Check the distance with the distanceTo() method
  3. If it is too big, chop off a part of a degree.
  4. Repeat 2)+ 3) until within an acceptable threshold.
Jason Fox
  • 5,115
  • 1
  • 15
  • 34