2013-01-17 40 views
0

我試圖獲取用戶的位置,並在iOS6與下面的代碼在圖形頁面顯示出來:setRegion:動畫:不會使區域變化

- (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 

這意味着什麼都沒有改變。我查了大多數問題相關的地圖,他們只是調用這個方法,並得到位置顯示在地圖的中心。

我想知道爲什麼我可以把用戶位置放到地圖中心。

回答

0

你可以只打開的MKMapView跟蹤模式

[mapView setTrackingMode:MKMapViewTrackingModeFollowsUser]; 
+0

然後你做錯了什麼Roozbeh。請提供一些背景知識,甚至可以提出一個新問題。 – Craig

0

你可以試試這個:

mMapView.showsUserLocation = YES;