1
votes

I need to find the closest coordinates (lat,lon) to a given coordinates-point, out of a set of given coordinates. Similarly to this question: Find the closest coordinate from a set of coordinates

However I also need to make sure it's "straight ahead", on the same line (with a certain maximum deviation of, say 15 degrees).

One way is to get the closest points - and then check the degrees between the origin and it for each and see it it's less than the maximum, is this the best way?

1

1 Answers

1
votes

when i work with gps i use OpenLayers so i don't know if this is a good prectice but you can use some OpenLayers features to avoid your problem

https://openlayers.org/en/latest/apidoc/ol.source.Vector.html#getClosestFeatureToCoordinate

like this:

import Vector from 'ol/source/vector';
import Feature from 'ol/feature';
import Point from 'ol/geom/point';
var vector = new Vector();

for(each coordinate that you want){
     var feature = new Feature({geometry: new Point(yourCoordinate)});
     vector.addFeature(feature);
}

var closestFeature = vector.getClosestFeature();
var closestPoint = closestFeature.getGeometry().getCoordinates();

so now you only need to use something like this

gist.github.com/conorbuck/2606166

and compare with the anglee to where you are facing