5

They both specify a map center and how big the box is.

So why use both?

Some function in MKMapview use one and some use the other

  • (MKCoordinateRegion)regionThatFits:(MKCoordinateRegion)region
  • (MKMapRect)mapRectThatFits:(MKMapRect)mapRect edgePadding:(UIEdgeInsets)insets

What's their difference?

More importantly, which one we should use to set the region we see?

There is no regionThatFits:edgePadding: by the way.

Sylvain Guillopé
  • 1,358
  • 9
  • 21
user4951
  • 32,206
  • 53
  • 172
  • 282

1 Answers1

9

A MKCoordinateRegion is defined using degrees coordinate of type CLLocationCoordinate2D which represents the latitude and longitude of a point on the surface of the globe.

MKMapRect represents an actual flat rectangle defined with view coordinate (x, y) on your map view.

You can use functions to do conversions for you like MKCoordinateRegionForMapRect

See http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MapKitFunctionsReference/Reference/reference.html

And to answer your final question, you would use MKCoordinateRegion which will define what region of the globe's surface you want to see and by definition it will set your zoom level.

Sylvain Guillopé
  • 1,358
  • 9
  • 21
  • What's that x and y contain? Latitude Longitude? – user4951 Aug 15 '12 at 04:11
  • No they are the map view x-axis and y-axis coordinate. `MKMapRect` and `CGRect` are basically the same. Except that you have to use `MKMapRect` if you want to do operations using the Map Kit Functions – Sylvain Guillopé Aug 15 '12 at 04:31
  • 1
    MKMapKit uses the Mercator map projection. The X and Y values correspond to your position on this projection. Apple has a good write-up on it: https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/MapKit/MapKit.html – psobko Jun 27 '14 at 17:46
  • Apple doesn't currently include `MKMapRectForCoordinateRegion` functionality; here's [a link to a SO question](https://stackoverflow.com/questions/9270268/convert-mkcoordinateregion-to-mkmaprect) with a couple of solutions. – bemental Feb 02 '21 at 10:51