When the bearing to a feature is calculated and the features is a line on a map (set of points connected together) and the centroid is false (hence it should give the closest point) it is not returning the correct angle, bat rather to the last point added at times.
Please show your relevant blocks
What variation do you believe you have on the bearing ?
I did a test of a linestring due North (360) and due South(180) of a marker, and the bearing improved the further away the linestring was. Within 500m I was seeing @1.5 degrees variation, whilst at 3000km only @ 0.3 degrees variation
This could be due to the calculations in the component using equatorial radius (as opposed to arithmetic mean).
I think this may be related to a bug reported in August 2022 that has not been resolved
The centeroid was set to false so as the description implies from a line having multiple points (not just one straight line) I believed that the bearing should be directed to the closest point on the line. From my testing it seems that when there is one line (hence just 2 points) then its quite accurate but then when multiple points are entered the bearing points toward the end part of the points rather then the closest
Is the solution to this to add a marker to the last/nearest "point" on the linestring and get the bearing to that from the first marker ?
No, I can do that as the line string is created on the fly as a plan. To take your point I can parse the list of points and check each intividual point as to how far is it. Still it doesn't solve it as the line between 2 point can be nearer than the two points to which the line is connected. Still its a bit taxing to code it and process heavy for the smartphone cpu.
Bearing to a point is giving accurate results but bearing to a feature is not, when the feature happens to be a line (a set of points connected together with a line). Distance to a point is quite accurate (not super precise either but it gives accaptable results). Distanct to a feature and the feature is a line also gives acceptable results but bearing to a feature is totaly out. Hopefully someone will solve the issue.
I ran a test, a simple linestring with just two points, and placed a second marker at the end of the linestring nearest to the first marker.
7.89
24.02
24.02
I measured the angle on the device screen using a protractor and this was @ 24
(I get the same results if centroids = false for linestring or marker 2)
Thanks for the demo. The bearing to feature gets incosistent results. Sometimes it hits the correct answer, other times no.
As you can see from your test the two should have the same degrees as the closest point on the line is the same as the location point shown by the marker and still you are getting different bearings.