简体   繁体   中英

How to zoom into user current location?

I wanna zoom into the user current location when the app starts in the MapKit. This is my code (in the viewDidLoad function):

Locate=[[CLLocationManager alloc]init];
Locate.delegate=self;
Locate.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
Locate.distanceFilter=kCLDistanceFilterNone;
[Locate startUpdatingLocation];
[super viewDidLoad];

//Region
MKCoordinateRegion myRegion;

//Center
CLLocationCoordinate2D center;
center.latitude=Locate.location.coordinate.latitude;
center.longitude=Locate.location.coordinate.longitude;

//Span
MKCoordinateSpan span;
span.latitudeDelta=0.3f;
span.longitudeDelta=0.3f;
//Set Region
myRegion.center=center;
myRegion.span=span;
[_MyMap setRegion:myRegion animated:YES];

Also I implemented the didUpdateLocation function with the same code as previous. The problem is that when the user location is changing (when the user is moving) the screen makes zoom at him but I can't move the screen, if I try to move it return to the user location immediately, so I can't see the whole map.

For Zooming the map you have to change the region values means center and span.once see this one Mapview Zoom

in my case i have used this one for moving the map when i click on particular button.

MKCoordinateSpan span = MKCoordinateSpanMake(30.5982f,0.0001f);
        CLLocationCoordinate2D coordinate = {36, 90};
        MKCoordinateRegion region = {coordinate, span};
        MKCoordinateRegion regionThatFits = [self.mapView regionThatFits:region];
        [self.mapView setRegion:regionThatFits animated:YES];

I solved this issue by adding touchesMoved function and I stopped updating the Location in this function. Solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM