Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I adapted the answer from @Cyril Godefroy and added the conversion from <a href="https://stackoverflow.com/questions/6775718/how-to-make-the-union-between-two-mkcoordinateregion">How to make the union between two MKCoordinateRegion</a></p> <pre><code>- (MKMapRect) mapRectForCoordinateRegion:(MKCoordinateRegion)coordinateRegion { CLLocationCoordinate2D topLeftCoordinate = CLLocationCoordinate2DMake(coordinateRegion.center.latitude + (coordinateRegion.span.latitudeDelta / 2.0), coordinateRegion.center.longitude - (coordinateRegion.span.longitudeDelta / 2.0)); MKMapPoint topLeftMapPoint = MKMapPointForCoordinate(topLeftCoordinate); CLLocationCoordinate2D bottomRightCoordinate = CLLocationCoordinate2DMake(coordinateRegion.center.latitude - (coordinateRegion.span.latitudeDelta / 2.0), coordinateRegion.center.longitude + (coordinateRegion.span.longitudeDelta / 2.0)); MKMapPoint bottomRightMapPoint = MKMapPointForCoordinate(bottomRightCoordinate); MKMapRect mapRect = MKMapRectMake(topLeftMapPoint.x, topLeftMapPoint.y, fabs(bottomRightMapPoint.x - topLeftMapPoint.x), fabs(bottomRightMapPoint.y - topLeftMapPoint.y)); return mapRect; } - (void) addSquareToMap:(CLLocation*)center withRadius:(float)radius{ MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, radius*2, radius*2); MKMapRect rect = [self mapRectForCoordinateRegion:region]; MKMapPoint leftBottom = MKMapPointMake(MKMapRectGetMinX(rect), MKMapRectGetMinY(rect)); MKMapPoint leftTop = MKMapPointMake(MKMapRectGetMinX(rect), MKMapRectGetMaxY(rect)); MKMapPoint rightTop = MKMapPointMake(MKMapRectGetMaxX(rect), MKMapRectGetMaxY(rect)); MKMapPoint rightBottom = MKMapPointMake(MKMapRectGetMaxX(rect), MKMapRectGetMinY(rect)); MKMapPoint rect[4] = {leftBottom, leftTop, rightTop, rightBottom}; MKPolygon *polygon = [MKPolygon polygonWithPoints:rect count:4]; poly.title = @"Square"; // Add it to the map [map addOverlay:poly]; } - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id &lt;MKOverlay&gt;)overlay{ if ([overlay isKindOfClass:[MKPolygon class]]){ MKPolygonView* aView = [[[MKPolygonView alloc] initWithPolygon:(MKPolygon*)overlay] autorelease]; aView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.15]; aView.strokeColor = [[UIColor redColor] colorWithAlphaComponent:0.7]; aView.lineWidth = 3; return aView; } return nil; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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