3

ウィンドウが一定の距離になるようにGoogleマップのズームレベルを設定する方法に出くわした人はいますか?

4

2 に答える 2

3
  1. 現在のズームレベルの使用でマップの幅を測定しgoogle.maps.geometry.spherical.computeDistanceBetween()map.getBounds()(ドクを参照)。

  2. 必要に応じて測定距離が広い場合は、2 で割ります。小さい場合は 2 倍します。

  3. 計算された幅がターゲットの幅よりも小さくなるか大きくなるまでこれを行い、乗算または除算する必要がある頻度を数えます。

  4. 数えた数値を現在のズーム値に加算/減算して、目標ズーム値を取得します。

注: 固定ズームレベルに制限されているため、マップを正確な幅に合わせることができません。これは概算にすぎません。

于 2012-08-21T14:16:17.000 に答える
1

I achieved a similar thing by creating a circle with the given distance and using that to get the bounds. The width of the map isn't quite the same as the circle as the API adds some padding.

//Accuracy in metres
var accuracy = 50; 

/* Create a circle but don't set the 'map' variable as we don't need to see circle on the map */
var circle = new google.maps.Circle({
                 center: map.getCenter(),
                 radius: accuracy
             });

//Get the new bounds from the circle
var bounds = circle.getBounds();

/* Fit the map to the size of the circle. Will be slightly bigger than the circle as the API adds a little padding */
map.fitBounds(bounds);
于 2013-09-29T13:37:14.777 に答える