【问题标题】:Find the closest coordinates "straight ahead", from a set of coordinates从一组坐标中找到最近的坐标“直接”
【发布时间】:2018-05-22 10:33:55
【问题描述】:

我需要在一组给定坐标中找到最接近给定坐标点的坐标(纬度,经度)。与此问题类似: Find the closest coordinate from a set of coordinates

不过,我还需要确保它是“直线前进”,在同一行 (有一定的最大偏差,比如 15 度)。

一种方法是获取最近的点 - 然后检查每个原点与原点之间的度数,看看它小于最大值,这是最好的方法吗?

【问题讨论】:

    标签: javascript gps coordinates


    【解决方案1】:

    当我使用 gps 时,我使用 OpenLayers,所以我不知道这是否是个好方法,但您可以使用一些 OpenLayers 功能来避免您的问题

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

    像这样:

    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();
    

    所以现在你只需要使用这样的东西

    gist.github.com/conorbuck/2606166

    并与您所面对的角度进行比较

    【讨论】:

    • 谢谢,但这似乎并不能确保最近的点在“同一条直线”上,这是我在我的问题中需要的限制。
    • 谢谢,是的,我以前看过...这是我在问题上描述的方式,仍然想知道是否还有其他更好的方式。
    • 我正在搜索它,我没有看到另一种“简单”的方法,使用它有问题吗?
    猜你喜欢
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多