1

特定の LatLng が Google マップのサークル内にあるかどうかを確認する必要があります (これらのいずれか: 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

必要なのは、緯度経度リストを Google 座標空間に変換するか、円を緯度経度座標空間に変換することです。

どのように変換を行うかは、使用している言語によって異なりますが、1 回限りの変換であれば、代わりに変換を行う Web サイトがあります。

円と同じ座標空間で緯度経度の位置を取得したら、単純なピタゴラス数学を使用して、位置が円の半径よりも小さいかどうかを判断できます(提案どおり)。

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 に答える