2

I have a MapPolyline drawn on a MapControl using anchor points from a GPX file. How can I detect when my position is off of the Polyline? I tried measuring the distance between the anchor points, and if it's off by 20 meters I raise a off course error. The problem with this is on a straight line, the anchor points are really far apart from one another and whilst I am still on the PolyLine, the off course error gets raised.

Take a look at this:

enter image description here

As you can see I am WAY off course. How to detect this?

Google's JavaScript API for Maps has a method called isLocationOnEdge() for exactly this purpose. Is there something like that for UWP?

Scavenger
  • 207
  • 2
  • 9
Gala
  • 2,592
  • 3
  • 25
  • 33
  • You could calculate the distance manually if it's not provided. Take one straight line from two connected points (A & B) out of the polyline and form a triangle with the Location Point. If any angle is >= than 90, the distance is the min of PointA to LP and PointB to LP; if all angles are < than 90, the distance is the perpendicular distance from LP to the line. Then apply the same formula to other lines and work out which one is the shortest. – Justin XL Aug 02 '17 at 15:16

1 Answers1

1

I solved this issue by porting Google's PolyUtil from the Google Maps SDK over to UWP, and it works a treat.

Here is the source code for PolyUtil.

Gala
  • 2,592
  • 3
  • 25
  • 33