Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your question talks about increasing the radius, but in this forum, "radius" will generally be construed as the radius of the circle measured in points/pixels.</p> <p>Clearly, that's not what you're asking for, though. Now, you've said you don't want to use a <code>MKMapView</code>, but I think it's a useful language to use when talking about your goals. Bottom line, you don't want to change the radius of the circle presented on the screen. You want to change the "span" (<a href="http://developer.apple.com/library/ios/documentation/MapKit/Reference/MapKitDataTypesReference/Reference/reference.html#//apple_ref/doc/uid/TP40009734-CH1-SW29" rel="nofollow noreferrer"><code>MKCoordinateSpan</code></a>) of the "region" (<a href="http://developer.apple.com/library/ios/documentation/MapKit/Reference/MapKitDataTypesReference/Reference/reference.html#//apple_ref/doc/uid/TP40009734-CH1-SW30" rel="nofollow noreferrer"><code>MKCoordinateRegion</code></a>) of the map which will be presented in the aforementioned circle.</p> <p>There are two ways of approaching this problem of how to draw a circle of fixed size that represents a projection of a map (but you don't, for some reason, want a map).</p> <ol> <li><p>Manually:</p> <ul> <li><p>Define a few useful properties:</p> <pre><code>@property (nonatomic) MKCoordinateRegion region; @property (nonatomic) CGRect frame; </code></pre> <p>The <code>region</code> defines the range of latitude and longitudes that will be presented in your user interface. The <code>frame</code> will be the screen coordinates in which we'll be presenting the those latitude and longitude points. Note, to do a visual representation of lat/long coordinates in a user interface you need both of these two aspects, something that defines what lat/long can be represented and something else that says where to put it on the screen.</p></li> <li><p>So, the first question is how you define the region. Here I'm defining the center coordinate and defining a region as being 500 meters from that:</p> <pre><code>CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(...); self.region = MKCoordinateRegionMakeWithDistance(coordinate, 500.0, 500.0); </code></pre> <p>You asked "how do I change the radius [i.e. the span] of what is shown?" You do that by changing the <code>region</code> variable which says that range of lat/long will be represented in the UI.</p></li> <li><p>Anyway, you can now you can add the circle to your screen:</p> <pre><code>- (void)addCircle { CGPoint center = CGPointMake(self.view.layer.bounds.size.width / 2.0, self.view.layer.bounds.size.height / 2.0); CGFloat radius = self.view.layer.bounds.size.width * 0.40; UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:0.0 endAngle:M_PI * 2.0 clockwise:YES]; self.frame = CGRectMake(center.x - radius, center.y - radius, radius * 2.0, radius * 2.0); CAShapeLayer *layer = [CAShapeLayer layer]; layer.path = [path CGPath]; layer.strokeColor = [[UIColor darkGrayColor] CGColor]; layer.fillColor = [[UIColor whiteColor] CGColor]; layer.lineWidth = 3.0; [self.view.layer addSublayer:layer]; self.view.backgroundColor = [UIColor lightGrayColor]; } </code></pre></li> <li><p>Write a routine to convert from a <code>CLLocationCoordinate2D</code> to a location on the screen:</p> <pre><code>- (CGPoint)determineCGPointFromCoordinate:(CLLocationCoordinate2D)coordinate { CGFloat percentX = (coordinate.longitude - self.region.center.longitude + self.region.span.longitudeDelta / 2.0) / self.region.span.longitudeDelta; CGFloat percentY = 1.0 - (coordinate.latitude - self.region.center.latitude + self.region.span.latitudeDelta / 2.0) / self.region.span.latitudeDelta; return CGPointMake(self.frame.origin.x + percentX * self.frame.size.width, self.frame.origin.y + percentY * self.frame.size.height); } </code></pre></li> <li><p>You can then add your points on your screen:</p> <pre><code>CGPoint center = [self determineCGPointFromCoordinate:coordinate]; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"spot.png"]]; imageView.center = center; [self.view addSubview:imageView]; </code></pre></li> </ul> <p>That yields us a view that looks like:</p> <p><img src="https://i.stack.imgur.com/BLcNR.png" alt="manual"></p></li> <li><p>Even easier, in my opinion, is to reevaluate your decision to not to use a map view. </p> <ul> <li><p>You could add a map view (see the <a href="http://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/MapKit/MapKit.html#//apple_ref/doc/uid/TP40009497-CH3-SW1" rel="nofollow noreferrer">Location Awareness Programming Guide</a>)</p></li> <li><p>Take your <code>CAShapeLayer</code> that you created, and rather than adding as a sublayer, you could instead clip the map to that circular <code>CAShapeLayer</code>:</p> <pre><code>[self.mapView.layer setMask:circleShapeLayer]; </code></pre></li> </ul> <p>And, once you've done all of the adding of annotations to the view, you get something like this:</p> <p><img src="https://i.stack.imgur.com/ilgCA.png" alt="map kit view"></p></li> </ol> <p>Personally, I like the map kit approach, as it gets you out of the business of manually calculating screen coordinates. But if you really don't want the map background there, you can do it manually.</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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