Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are several ways to do this.</p> <p>You could create an <code>MKCoordinateRegion</code> by figuring out the <code>center</code> point and then the <code>span</code> is the absolute difference in degrees between the corners.</p> <p>Or you could create an <code>MKMapRect</code> by using the MapKit function <code>MKMapPointForCoordinate</code>. To get the <code>origin</code>, figure out the northwest coordinate and convert it to an <code>MKMapPoint</code>. To get the <code>width</code> and <code>height</code>, get the absolute difference in <strong>mappoints</strong> between the corners (convert the corners from coordinates to <code>MKMapPoint</code>s using the function first).</p> <p>Another quick way is a slight trick using the <code>MKMapRectUnion</code> function. Create a zero-size <code>MKMapRect</code> from each coordinate and then merge the two rects into one big rect using the function:</p> <pre><code>MKMapPoint swPoint = MKMapPointForCoordinate(SWCoordinate); MKMapRect swRect = MKMapRectMake(swPoint.x, swPoint.y, 0, 0); MKMapPoint nePoint = MKMapPointForCoordinate(NECoordinate); MKMapRect neRect = MKMapRectMake(nePoint.x, nePoint.y, 0, 0); MKMapRect rect = MKMapRectUnion(swRect, neRect); </code></pre> <p>Remember that the map view will still make its own adjustments to the rect you request based on the proportions of the map view and the required zoom. (If you want to know what that adjusted rect will be, call the map view's <code>mapRectThatFits:</code> method.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload