同样的方法在ios 6中运行良好 我使用的是didUpdateToLocation方法,其实现如下: -
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)Location fromLocation:(CLLocation *)oldLocation
{
if(appDelegate->mapView )
{
if(Span)
{
[appDelegate->mapView setRegion:MKCoordinateRegionMake(Location.coordinate, MKCoordinateSpanMake(0.01f, 0.01f)) animated:YES];
Span = NO;
}
else
{
[appDelegate->mapView setCenterCoordinate:Location.coordinate animated:YES];
}
}
}
请建议应该做什么,以便跟踪用户的位置,用户也应该能够在地图上放大和缩小。地图也应该围绕当前的GPS位置。
答案 0 :(得分:0)
我使用它来在加载地图时缩放用户位置。
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView {
NSLog(@"mapViewDidFinishLoadingMap");
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self zoomMapView:mapView ToUserLocation:mapView.userLocation.coordinate];
}); }
-(void)zoomMapView:(MKMapView*)mapView ToUserLocation:(CLLocationCoordinate2D)coordinate {
if (!isZoomed) {
isZoomed=TRUE;
MKCoordinateRegion region = mapView.region;
MKCoordinateSpan span;
region.center = coordinate;
span.latitudeDelta = 0.02;
span.longitudeDelta = 0.02;
region.span=span;
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
[mapView setShowsUserLocation:YES];
[mapView setRegion:region animated:YES];
} }
只要您想缩放用户的当前位置,就可以调用-(void)zoomMapView:(MKMapView*)mapView ToUserLocation:(CLLocationCoordinate2D)coordinate
方法。