I want to know the radius of visible area in iphone screen, as I will zoomout and zoom in the visible area will change, so I want to know the radius of that particular area, how can I do it?
Asked
Active
Viewed 3,799 times
3
-
Did you get solution for this?let me know , I have same senario – Pooja Shah Mar 17 '15 at 07:15
2 Answers
4
Its not radius what is required.
You need to use the region parameter from mapView.
Check out apple docs, it is pretty much clear from those.
Go thru this tutorial. It will help you a lot
specifically you need to set 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;
}
Cheers :)

SeriousSam
- 219
- 2
- 14
-
Swapz, I will surely, as I will test and and it will work, else I will comment you back dear – Chatar Veer Suthar Sep 28 '11 at 07:46
-
I have different scenario, I have to sent radius of area, then server will return the data of offices in that region, so I might need radius, else has to change the xml with different wayy – Chatar Veer Suthar Sep 28 '11 at 08:09
-
ya dude.. when u change the region and span, send the latitude longitude parameters again, and the server will return you back objects corresponding to those areas. Check googles reqversegeocoding api for example, it works the same way you can refer that. – SeriousSam Sep 28 '11 at 08:13
-
means I can't get radius of visible MKMapView are, are you sure about? – Chatar Veer Suthar Sep 28 '11 at 08:15
-
when u change the region and span, send the latitude longitude parameters again, and the server will return you back objects corresponding to those areas. Check googles reqversegeocoding api for example, it works the same way you can refer that. Check it here [api](http://code.google.com/apis/maps/documentation/geocoding/#JSON) check the **Reverse Geocoding (Address Lookup)** section here. – SeriousSam Sep 28 '11 at 08:18
-
Ya, but the webservice I am using is taking radius, so can I take radius from longitude and latitude from current visible are? – Chatar Veer Suthar Sep 28 '11 at 08:21
-
Normally for Maps, your map region is a rectangular thing. Cos all of us use google maps, all the access mechanisms comply with the same. So regarding your webservice I dont know you will have to consult that with your service provider. – SeriousSam Sep 28 '11 at 12:03
-
0
I might be misunderstanding the question, but isn't it as simple as:
- (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);
}

Shaheen Ghiassy
- 7,397
- 3
- 40
- 40