2012-02-14 80 views
1

我按照以下tutorial將地圖嵌入到我的應用程序中。如何顯示用戶當前位置 - GPS

後來我添加了一個按鈕,當用戶點擊它時,我會向用戶顯示他們當前的位置;這裏是我的代碼:

-(void)showUserLocation { 
self.mapView.showsUserLocation=YES; 
} 

但是,當映射指向俄羅斯,我的用戶的位置是在倫敦我怎樣才能將地圖移動到我的用戶位置?

詳細: 當我點擊按鈕Show User current location,它繪製地圖上的藍色圓點。但是,這並沒有把我帶到那個地步。如果地圖指向俄羅斯,並且我的用戶位置在倫敦,如何將地圖移動到指向我的用戶位置?

回答

3

看看這個的MKMapView方法:mapView:didUpdateUserLocation

setCenterCoordinate:animated:

MKUserLocation *location = self.mapView.userLocation; 
[self.mapView setCenterCoordinate: CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longutde) animated:YES]; 

這應該被優選地使用這種方法MKMapViewDelegate實現