How to find the radius of the visible visible area of ​​the MKMapView screen?

I want to know the radius of the visible area on the iphone screen, since I will zoom in and out the visible area, so I want to know the radius of this specific area, how can I do this?

+3
source share
3 answers

No radius radius required.

You need to use the region parameter from mapView.

Check out apple docs, it's pretty clear from them.

Go through this tutorial. This will help you a lot.

demo for icode blog

in particular, you need to install something like this.

MKCoordinateSpan span = [self coordinateSpanWithMapView:self centerCoordinate:centerCoordinate andZoomLevel:zoomLevel]; MKCoordinateRegion region = MKCoordinateRegionMake(centerCoordinate, span); [self setRegion:region animated:animated]; 

where span can be calculated as

 - (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; } 

Greetings :)

+4
source

Perhaps I do not understand the question, but not so simple:

 - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { CGFloat latD = mapView.region.span.latitudeDelta; CGFloat lngD = mapView.region.span.longitudeDelta; NSLog(@"This is the latitude delta of the visible map: %f", latD); NSLog(@"This is the longitude delta of the visible map: %f", lngD); } 
0
source

I'm stuck in a problem

I drew a shape in the form of a map and even got the center coordinate. It remains to find the radius from the central coordinate.

if anyone can help me.

[This is the shape I drew, the annotation is the center point, you need to find the radius and then draw a circle on it]

https://i.stack.imgur.com/iVUpA.png

0
source

Source: https://habr.com/ru/post/1215511/


All Articles