Luc
Luc

Reputation: 17072

Zoom level limited in my google map iOS app

I use the following code to display a map center on the user's location:

...
// start off by default current position
AppManager *appManager = [AppManager sharedManager];
MKCoordinateRegion newRegion;
newRegion.center.latitude = [appManager.currentlatitude floatValue];
newRegion.center.longitude = [appManager.currentlongitude floatValue];
newRegion.span.latitudeDelta = 0.06;
newRegion.span.longitudeDelta = 0.06;
[self.mapView setRegion:newRegion animated:YES];
[self.view insertSubview:mapView atIndex:0];
...

The thing is, I do not manage to decrease the zoom level enough when playing with "newRegion.span.latitudeDelta" and "newRegion.span.longitudeDelta" values. The zoom only show a zone of something like 30 kms wide when I'd like to have several hundreds.

For what I saw, a value of 0.06 for longitudeDelta should show 180 degre (half of the earth) (for a latitude 0), then for a latitude of 43, I think I should see more than 30 km.

Any idea ?

Upvotes: 2

Views: 1587

Answers (1)

user467105
user467105

Reputation:

The latitudeDelta and longitudeDelta are in degrees so a value of 0.06 is a relatively small distance in km. To show "half of the Earth", you'd have to set the longitudeDelta to 180.0.

If you know the distance (eg. in km) you want to show, it will be easier to use the MKCoordinateRegionMakeWithDistance function instead of trying to do the conversion yourself:

CLLocationCoordinate2D newCenter = 
    CLLocationCoordinate2DMake([appManager.currentlatitude floatValue], 
                               [appManager.currentlongitude floatValue]);

MKCoordinateRegion newRegion = 
    MKCoordinateRegionMakeWithDistance(newCenter, 200000, 200000);

The last two parameters are latitudinalMeters and longitudinalMeters so the above example sets the span to 200 km x 200 km.

Remember the map view will then adjust the region as needed based on the map view's proportions and displayable zoom level.

Upvotes: 7

Related Questions