【问题标题】:Finding whether the coordinate is within polygon查找坐标是否在多边形内
【发布时间】:2020-02-13 21:42:30
【问题描述】:

我想知道给定坐标(纬度和经度)是否在给定的 4 个坐标内。

即,如果我有 A、B、C、D 和 E 的纬度、经度,并且我想检查 E 是否在 A、B、C 和 E 之内。

我该怎么做?

我试图从Google Map Coordinates LatLngBound class - contains 看到这个例子。

我能看到的例子是这样的

var bounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(54.69726685890506,-2.7379201682812226),
    new google.maps.LatLng(55.38942944437183, -1.2456105979687226)
);
var center = bounds.getCenter();  // still returns (55.04334815163844, -1.9917653831249726)
var x = bounds.contains(center);  // now returns true

它只有 2 个坐标,如 A&B。没有C&D的坐标怎么可能?

【问题讨论】:

    标签: javascript google-maps location latitude-longitude google-location-services


    【解决方案1】:

    这是因为这是使用LatLngBounds 创建的矩形,而不是多边形。如果您有一个盒子的两个角,则可以假设其他两个角。您只需要指定对角。在您的示例中,您只需将 A 和 D 或 B 和 C 作为一对发送,其他两个可以忽略。如果您需要一个多边形,那么您要创建a polygon,然后确定它是否包含带有google.maps.geometry.poly.containsLocation(point, polygon) 的点。

    containsLocation() Documentation here.

    Full example here.

    【讨论】:

    • 嘿,谢谢你的解释,现在我明白了.. 所以我会单独经过西南和东北
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 2019-04-26
    相关资源
    最近更新 更多