【问题标题】:setRegion:animated: does not make region changesetRegion:animated: 不改变区域
【发布时间】:2013-01-17 06:21:12
【问题描述】:

我正在尝试获取用户位置并将其显示在 mapView 中,并在 iOS6 中使用以下代码:

- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
if (locations.count>0) {
    for (CLLocation *location in locations) {
        [locationList addObject:location];

        if (location != nil) {
            // Zoom to the current user location.
            MKCoordinateRegion userLocation =[mapView regionThatFits: MKCoordinateRegionMakeWithDistance(location.coordinate, 150.0, 150.0)];
            [mapView setRegion:userLocation animated:YES];
            NSLog(@"%f,%f", mapView.centerCoordinate.latitude,mapView.centerCoordinate.longitude);
            NSLog(@"%f,%f", mapView.region.span.latitudeDelta,mapView.region.span.longitudeDelta);
        }
    }
}

}

但位置更新后,[mapView setRegion:userLocation animated:YES] 不会对mapView 的区域进行任何更改,但用户位置可以显示为蓝点。 NSLog 打印如下:

nan,nan
0.000000,360.000000

这意味着没有任何改变。我检查了大多数与地图相关的问题,他们只是调用此方法并在地图中心获取位置显示。

我想知道为什么我可以把用户位置放到地图中心。

【问题讨论】:

    标签: objective-c ios6 mkmapview


    【解决方案1】:

    你可以打开 MKMapView 跟踪模式

    [mapView setTrackingMode:MKMapViewTrackingModeFollowsUser];
    

    【讨论】:

    • 那么你做错了什么Roozbeh。请提供一些背景信息,甚至可以提出一个新问题。
    【解决方案2】:

    你可以试试这个:

    mMapView.showsUserLocation = YES;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-21
      • 2021-07-23
      • 1970-01-01
      相关资源
      最近更新 更多