6

タイトルのように、すべての地域でメートルまでのサイズ幅を計算する方法を知っている人はいますか?

私はzoomScaleを取得する方法を見つけました。

CLLocationDegrees longitudeDelta = myMapView.region.span.longitudeDelta;
CGFloat mapWidthInPixels = myMapView.bounds.size.width;
double zoomScale = longitudeDelta * MERCATOR_RADIUS * M_PI / (180.0 * mapWidthInPixels);

しかし、結果が何を意味するのかわかりません。サイズ幅のメーターまたは行20fを取得したい場合は、mapWidthInPixelsを20に変更します。

4

3 に答える 3

8

ここで数式の詳細な説明を見つけることができます:経度緯度をメートルに変換します。

サンプルコード:

CLLocationDegrees deltaLatitude = self.mapView.region.span.latitudeDelta;
CLLocationDegrees deltaLongitude = self.mapView.region.span.longitudeDelta;
CGFloat latitudeCircumference = 40075160 * cos(self.mapView.region.center.latitude * M_PI / 180);
NSLog(@"x: %f; y: %f", deltaLongitude * latitudeCircumference / 360, deltaLatitude * 40008000 / 360);

Mark Ransomの功績

于 2012-12-20T09:08:24.513 に答える
7

これは私にとってうまくいきました。私の解決策はSwiftにありますが、Obj-Cは似ています。

スウィフト:

let mRect: MKMapRect = self.mapView.visibleMapRect
        let eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect))
        let westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect))
        let currentDistWideInMeters = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint)
        let milesWide = currentDistWideInMeters / 1609.34  // number of meters in a mile
        println(milesWide)

Obj-C (以下のコードの元の貢献者への賛辞https://stackoverflow.com/a/5813609/3750109 )

MKMapRect mRect = self.mapView.visibleMapRect;
        MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect));
        MKMapPoint westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect));

        self.currentDistWideInMeters = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint);
于 2015-04-14T18:16:06.607 に答える
1

経度のメートル単位の距離は、緯度が高くなるにつれて変化します。同じ経度の値でも、赤道から離れるにつれてメートル単位で小さくなります。おそらく最良の方法はCLLocation、中央左と中央右に 2 つの を作成し、 を使用-distanceFromLocation:してそれらの間の距離をメートル単位で取得することです。

于 2012-12-20T11:56:54.730 に答える