当应用程序在 MapKit 中启动时,我想放大用户当前位置。
这是我的代码(在 viewDidLoad 函数中):
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];
我还实现了
didUpdateLocation
功能与之前的代码相同。问题是当用户位置改变时(当用户移动时)屏幕会放大他但我不能移动屏幕,如果我尝试移动它会立即返回用户位置,所以我不能查看整个 map 。
最佳答案
要缩放 map ,您必须更改区域值意味着中心和跨度。一旦看到这个 Mapview Zoom
在我的情况下,当我单击特定按钮时,我使用这个来移动 map 。
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];
关于ios - 如何放大用户当前位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15833370/