Javascript 计算从车床(或圆中的点)到车床的距离-谷歌地图v3

Javascript 计算从车床(或圆中的点)到车床的距离-谷歌地图v3,javascript,google-maps-api-3,point-in-polygon,Javascript,Google Maps Api 3,Point In Polygon,我需要找出是否某些LatLngs在谷歌地图圈内(其中一个:)。我该怎么做呢?我制作圆圈的标记是: geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); circlemarker = new g

我需要找出是否某些LatLngs在谷歌地图圈内(其中一个:)。我该怎么做呢?我制作圆圈的标记是:

geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        circlemarker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
        THEradius = parseFloat(THEradius);
         var populationOptions = {
          strokeColor: "#BDAEBB",
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: "#BDAEBB",
          fillOpacity: 0.5,
          map: map,
          center: results[0].geometry.location,
          radius: THEradius
         };
        cityCircle = new google.maps.Circle(populationOptions);
        map.fitBounds(cityCircle.getBounds());
    }
});

我可以使用半径吗?

您需要做的是将纬度列表转换为谷歌坐标空间,或将圆转换为纬度坐标空间

你如何进行转换取决于你使用的语言,但是如果是一次性的,有些网站会为你进行转换

一旦你得到了与你的圆在同一个坐标空间中的横向位置,你可以使用简单的毕达哥拉斯数学来计算这个位置是否小于圆的半径(如你所建议的)

其中:

OPP is the difference in x direction from the centre of the circle
ADJ is the difference in y direction from the centre of the circle.
HYP is the distance in a straight line from the centre of the circle

您需要做的是将lat-lon列表转换为google坐标空间,或将圆转换为lat-lon坐标空间

你如何进行转换取决于你使用的语言,但是如果是一次性的,有些网站会为你进行转换

一旦你得到了与你的圆在同一个坐标空间中的横向位置,你可以使用简单的毕达哥拉斯数学来计算这个位置是否小于圆的半径(如你所建议的)

其中:

OPP is the difference in x direction from the centre of the circle
ADJ is the difference in y direction from the centre of the circle.
HYP is the distance in a straight line from the centre of the circle
var distance=google.maps.geometry.spherical.ComputedIstanceBeween(
结果[0]。几何体。位置,其他;
如果(距离
var distance=google.maps.geometry.spheremic.ComputedDistanceBeween(
结果[0]。几何体。位置,其他;

如果(距离在数学方面,要在2D中找到从一点到另一点的距离,请使用:

(上面有效地计算了从一个点到另一个点的矢量)

从1到2的距离=sqrt(X^2+Y^2)

然后你可以将其与半径进行比较。如果距离小于半径,则该点位于圆内


首先需要获取圆心对应的点和要比较的点。这两个点必须位于同一坐标空间中。

在数学方面,要在2D中找到从一个点到另一个点的距离,请使用:

(上面有效地计算了从一个点到另一个点的矢量)

从1到2的距离=sqrt(X^2+Y^2)

然后你可以将其与半径进行比较。如果距离小于半径,则该点位于圆内


你需要首先获得圆心对应的点和你要比较的点。它们必须在同一个坐标空间中。

顺便说一句,你不能使用毕达哥拉斯定理,因为地球不是平的!现场的第一个答案很好,非常感谢,绝对是最好的解决方案,也是我一直在寻找的解决方案r、 你知道这个选项是否有任何请求限制吗?文档中没有提到任何限制。我不确定这个函数是在本地还是在服务器上计算的。顺便说一句,你不能使用毕达哥拉斯定理,因为地球不是平的!在网站上的第一个答案很好,非常感谢,绝对是最好的解决方案,也是我正在寻找的解决方案ng。您知道此选项是否有任何请求限制吗?文档中没有提到任何限制。我不确定该函数是在本地还是在服务器上评估的。
var distance = google.maps.geometry.spherical.computeDistanceBetween(
       results[0].geometry.location, otherLatLng);

if (distance <= THEradius) {...} else {...}
X = X1 - X2
Y = Y1 - Y2