What's the difference between MKMapRect and MKCoordinateRegion
Asked Answered
L

1

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.

Lobell answered 15/8, 2012 at 3:46 Comment(0)
C
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.

Carpentaria answered 15/8, 2012 at 3:57 Comment(4)
What's that x and y contain? Latitude Longitude?Lobell
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 FunctionsWarmedover
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: developer.apple.com/library/ios/documentation/userexperience/…Sundried
Apple doesn't currently include MKMapRectForCoordinateRegion functionality; here's a link to a SO question with a couple of solutions.Oregano

© 2022 - 2024 — McMap. All rights reserved.