How to zoom into user current location?

喜夏-厌秋 提交于 2019-12-13 02:55:25

问题


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.


回答1:


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];



回答2:


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



来源:https://stackoverflow.com/questions/15833370/how-to-zoom-into-user-current-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!