IOS, how to calculate the width of the size in meters in each region (any location and any scaling)

as a name, does anyone know how to calculate the width of the size in meters in each region, means in every place and any scaling.

I found how to get zoomScale.

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

But I do not know what the result means, if I want to get meters for the width of the size, or maybe the line 20f, I change mapWidthInPixels to 20, is that true?

+4
source share
3 answers

You can find a detailed explanation of the formula here: convert longitude latitude to meters .

Code example:

 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 Credits

+6
source

This worked great for me. My solution is in Swift, however Obj-C is similar.

Swift:

 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 (welcomes the initial contributor to the fooobar.com/questions/256521 / ... code below)

 MKMapRect mRect = self.mapView.visibleMapRect; MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect)); MKMapPoint westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect)); self.currentDistWideInMeters = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint); 
+5
source

The distance in longitudinal meters will change as latitude increases. The same value of longitude becomes less in meters when you move further from the equator. The best way would probably be to create two CLLocation in the center on the left and in the center on the right, then use -distanceFromLocation: to get the distance between them in meters.

+1
source

All Articles