如何在和中心用户位置放大“点”?我用尽了一切我已经在这里和其他网站上找到,但我似乎无法得到它的权利。如何放大和中心用户位置(Objective-C的)
请帮帮我!
编辑:我一直在努力,实现viewDidAppear这行代码。我发现它在一个古老的线程的地方,但它似乎并没有工作了...
[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
如何在和中心用户位置放大“点”?我用尽了一切我已经在这里和其他网站上找到,但我似乎无法得到它的权利。如何放大和中心用户位置(Objective-C的)
请帮帮我!
编辑:我一直在努力,实现viewDidAppear这行代码。我发现它在一个古老的线程的地方,但它似乎并没有工作了...
[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
我创建的地图程序,而不要使用MapKit查看,它完美的工作!
下面的代码:
[super viewDidLoad];
self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.mapView setShowsUserLocation:YES];
[self.mapView setDelegate:self];
[self.view addSubview:self.mapView];
[mapView setMapType:MKMapTypeHybrid];
}
#pragma mark - MKMapViewDelegate Methods
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
[self.mapView setRegion:MKCoordinateRegionMake(userLocation.coordinate, MKCoordinateSpanMake(0.1f, 0.1))animated:YES];
}
您是否尝试过的地图设置区域,我列出万一你错过了什么的所有步骤,让我知道你错过了哪些,我会提供代码。
在viewDidLoad
或viewDidAppear
哪个适合你的流量。你必须启动地图和钩更新位置,一旦地图初始化,并聆听位置更新您的didUpdateUserLocation
您需要设置区域这样
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
//Mapview is your map on display,
CLLocationCoordinate2D coord = self.mapView.userLocation.coordinate;
//Create a region with a 1000x1000 meter around the user location
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(coord, 1000, 1000);
//Set the region of your mapview so the user location is in center and update
[self.mapView setRegion:viewRegion];
}
更新你已经尝试了什么你的问题。解释你对代码有什么问题。 – rmaddy
我已经编辑现在:) – Yomo
您是否验证了'mapView'不是'nil'?你确认'mapView.userLocation'不是'nil'吗? – rmaddy