Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Its not radius what is required.</p> <p>You need to use the region parameter from mapView. </p> <p>Check out apple docs, it is pretty much clear from those.</p> <p>Go thru this tutorial. It will help you a lot</p> <p><a href="http://www.icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/" rel="nofollow">icode blog mapkit demo</a></p> <p>specifically you need to set something like this..</p> <pre><code>MKCoordinateSpan span = [self coordinateSpanWithMapView:self centerCoordinate:centerCoordinate andZoomLevel:zoomLevel]; MKCoordinateRegion region = MKCoordinateRegionMake(centerCoordinate, span); [self setRegion:region animated:animated]; </code></pre> <p>where span can be calculated as</p> <pre><code>- (MKCoordinateSpan)coordinateSpanWithMapView:(MKMapView *)mapView centerCoordinate:(CLLocationCoordinate2D)centerCoordinate andZoomLevel:(NSUInteger)zoomLevel { // convert center coordiate to pixel space double centerPixelX = [self longitudeToPixelSpaceX:centerCoordinate.longitude]; double centerPixelY = [self latitudeToPixelSpaceY:centerCoordinate.latitude]; // determine the scale value from the zoom level NSInteger zoomExponent = 20 - zoomLevel; double zoomScale = pow(2, zoomExponent); // scale the map’s size in pixel space CGSize mapSizeInPixels = mapView.bounds.size; double scaledMapWidth = mapSizeInPixels.width * zoomScale; double scaledMapHeight = mapSizeInPixels.height * zoomScale; // figure out the position of the top-left pixel double topLeftPixelX = centerPixelX - (scaledMapWidth / 2); double topLeftPixelY = centerPixelY - (scaledMapHeight / 2); // find delta between left and right longitudes CLLocationDegrees minLng = [self pixelSpaceXToLongitude:topLeftPixelX]; CLLocationDegrees maxLng = [self pixelSpaceXToLongitude:topLeftPixelX + scaledMapWidth]; CLLocationDegrees longitudeDelta = maxLng - minLng; // find delta between top and bottom latitudes CLLocationDegrees minLat = [self pixelSpaceYToLatitude:topLeftPixelY]; CLLocationDegrees maxLat = [self pixelSpaceYToLatitude:topLeftPixelY + scaledMapHeight]; CLLocationDegrees latitudeDelta = -1 * (maxLat - minLat); // create and return the lat/lng span MKCoordinateSpan span = MKCoordinateSpanMake(latitudeDelta, longitudeDelta); return span; } </code></pre> <p>Cheers :)</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