2017-10-03 7 views

答えて

2

MapViewからonRegionChange経由でリージョンオブジェクトを取得すると、そのオブジェクトには4つのプロパティが含まれます。

const region = { 
    latitude: 37.78825, 
    longitude: -122.4324, 
    latitudeDelta: 0.0922, 
    longitudeDelta: 0.0421, 
} 

デルタ値を使用して、表示する最小と最大のポイントとの違いのためのものです。この情報を

MKMapView and Zoom Levels: A Visual Guideからの画像)

example of delta points

あなたはMapViewのの4つの隅を計算することができます(境界をマッピングする)か、ズームのレベルを設定するためにそれらを使用することができます。

(計算上の多少の誤差があるかもしれないので、テストされていない)

我々は以下の例で与えられた領域の上に私たちのMapViewを設定した場合は、私たちの四隅には、以下の計算された位置になります。

const leftTopLongitude = region.longitude - (region.longitudeDelta/2); 
const rightTopLongitude = region.longitude + (region.longitudeDelta/2); 
const leftTopLatitude = region.latitude + (region.latitudeDelta/2); 
const rightTopLatitude = region.latitude + (region.latitudeDelta/2); 

const leftBottomLongitude = region.longitude - (region.longitudeDelta/2); 
const rightBottomLongitude = region.longitude + (region.longitudeDelta/2); 
const leftBottomLatitude = region.latitude - (region.latitudeDelta/2); 
const rightBottomLatitude = region.latitude - (region.latitudeDelta/2); 
+0

ok bro、私に確認してみましょう。 tnx :) –

+0

すばらしい仲間、ちょうどチャームのように機能します。 Thnx a ton bro :) –

+0

@Beckyはうれしいです。 – bennygenel

関連する問題