Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKMapView Setting Initial Zoom level

I use this code in viewWillLayoutSubviews to set the initial region of my map.

CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(13.747266, 100.526804);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord, 800, 800)];
[self.mapView setRegion:adjustedRegion animated:YES];
NSLog(@"%f",adjustedRegion.span.latitudeDelta);

However, the initial zoom level doesn't work. The coordinate is correct, but it always zoom in to probably the max level. I check the span of the region and got 0.0. How do I fix this.

like image 801
harinsa Avatar asked May 23 '13 04:05

harinsa


People also ask

How do you get zoom level in Mkmapview?

The easiest way to get an Integer of the current zoom level, is by using the MapView function: regionDidChangeAnimated. This function recognizes every change in zoom and will give you the basis for the calculation of the zoom factor.

How do I zoom in on mapView?

MKCoordinateRegion zoomIn = mapView. region; zoomIn. span. latitudeDelta *= 0.5; [mapView setRegion:zoomIn animated:YES];

What is Mkcoordinatespan in Swift?

Creates a coordinate span that represents a width and height on a map.

How do you zoom map in react native?

It takes a region object which has latitudeDelta and longitudeDelta . Use these to set the zoom level. Updated: in a Region object the latitude and longitude specify the center location and latitudeDelta and longitudeDelta specify the span of the viewable map area.


1 Answers

You need to set your span.So give your span value here.

adjustedRegion.span.longitudeDelta  = 0.005;
adjustedRegion.span.latitudeDelta  = 0.005;
like image 51
Dharmbir Singh Avatar answered Sep 21 '22 00:09

Dharmbir Singh