2014-03-04 42 views
1

同样的方法在IOS工作正常6 我使用didUpdateToLocation方法及其实现如下: -setcentercoordinate不会允许放大和缩小在IOS 7

- (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方法。

+0

非常感谢您的快速回复。实际上,GPS位置以用户当前位置为中心。但是当我手动尝试放大和缩小使用缩放功能时,地图不允许我缩放,缩放级别仍然保持不变。 – user3378550

+0

你是否检查'userInteraction'是否为地图视图启用 – Bonnie

+0

我认为地图视图的用户交互是默认启用的,因为代码在iOS6上工作得非常好 – user3378550