1

我需要确定某些 LatLngs 是否在 Google Maps Circle 内(其中之一: http ://code.google.com/apis/maps/documentation/javascript/overlays.html#Circles )。我将如何解决这个问题?我制作圆圈的标记是:

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

我可以只使用半径吗?

4

3 回答 3

2
var distance = google.maps.geometry.spherical.computeDistanceBetween(
       results[0].geometry.location, otherLatLng);

if (distance <= THEradius) {...} else {...}

我希望这对你有用。请参阅http://code.google.com/apis/maps/documentation/javascript/reference.html#spherical

于 2011-09-01T13:36:03.907 回答
1

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

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

一旦您在与圆相同的坐标空间中获得了经纬度位置,您就可以使用简单的毕达哥拉斯数学来计算该位置是否小于圆的半径(如您所建议的那样)。

HYP = (OPP^2 * ADJ^2)^0.5

在哪里:

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
于 2011-09-01T13:26:18.260 回答
1

在数学方面,要在 2D 中找到一个点到另一个点的距离,请使用毕达哥拉斯

X = X1 - X2
Y = Y1 - Y2

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

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

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

您需要首先获取与圆心相对应的点和您要比较的点。这些必须在相同的坐标空间中。

于 2011-09-01T13:36:08.773 回答