Note that there are some explanatory texts on larger screens.

plurals
  1. POMKMapView Region
    text
    copied!<p>I have a question regarding setting the region on my MKMapView.</p> <p>I need to set the mapview to display a specific region when my view first loads.</p> <p>The north east and south west latitude and longitude of this region is:</p> <pre><code>North East Coordinate Lat:59.623724 Long:2.911587 South West Coordinate Lat:49.004833 Long:-11.361825 </code></pre> <p>Further to this, I would like to 'lock' the mapview to this region. Ideally the lock will be transparent, i.e: the coordinates above represent the maximum extent of the MKMapView. However if it is simply a case of checking the northeast and southwest coordinates within</p> <pre><code>- (void)mapView:(MKMapView *)aMapView regionDidChangeAnimated:(BOOL)animated </code></pre> <p>and resetting the view if they exceed my maximum range, that would be acceptable to me also.</p> <p>Many thanks for any pointers on this matter.</p> <p>EDIT: Regarding the first part of my question, I have figured out I can set the initial region on the MKMapView using the following code:</p> <pre><code>CLLocationCoordinate2D neCoord; neCoord.latitude = 59.787643; neCoord.longitude = 3.025857; CLLocationCoordinate2D swCoord; swCoord.latitude = 49.394171; swCoord.longitude = -11.036642; MKCoordinateRegion region; region.center.latitude = neCoord.latitude - (neCoord.latitude - swCoord.latitude) * 0.5; region.center.longitude = neCoord.longitude + (swCoord.longitude - neCoord.longitude) * 0.5; region.span.latitudeDelta = fabs(neCoord.latitude - swCoord.latitude); // Add a little extra space on the sides region.span.longitudeDelta = fabs(swCoord.longitude - neCoord.longitude); // Add a little extra space on the sides region = [self.mapView regionThatFits:region]; [self.mapView setRegion:region animated:YES]; </code></pre>
 

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