這是一個有些奇怪,但我一直在試圖尋找2天的解決方案直,設置地圖區域,但似乎沒有任何工作 這裏是我的代碼:MKCoordinateRegion始終鎖定在中心座標0,0上?
-(void)viewWillAppear:(BOOL)animated{
//[self step1locationupdate];
Maplocation.showsUserLocation=YES;
MKCoordinateRegion mapRegion;
mapRegion.center.longitude=self.currentProduct.shop.longcoordinate;
mapRegion.center.latitude=self.currentProduct.shop.latcoordinate;
NSLog(@"The USer Location are :%f",mapRegion.center.latitude);
mapRegion.span.latitudeDelta= 2;
mapRegion.span.longitudeDelta= 2;
[Maplocation setRegion:mapRegion animated:YES];
NSLog(@"The USer Location are :%f %f",Maplocation.userLocation.coordinate.latitude,Maplocation.userLocation.coordinate.longitude);
}
的NSLog的爲malocation。 userlocation.coordinate在啓動時始終爲0。 我將它到viewDidLoad中部分&相同的代碼也沒有什麼區別
請幫助
你也切換了fr om使用'self.currentProduct.shop.longcoordinate'到'Maplocation.userLocation.coordinate'來創建要賦予'Maplocation'的區域。對我來說,這表明你的'curenntProduct.shop.longcoordinate'尚未設置。 5秒的延遲很奇怪,雖然它可能在你的測試用例中工作,但用戶位置可能需要更長時間才能在沒有良好GPS接收的其他設備上準備好。你最好從MKMapViewDelegate協議中添加一個方法,比如didUpdateUserLocation,一旦位置準備就會被調用。 – Craig
嗯,我早些時候嘗試過DidUpdateUserLocation,但它從來沒有被調用過,這就是爲什麼我想出了延遲來觸發定時器的位置,因爲它自己沒有被觸發 – TALAA
didUpdateUserLocation將被調用,如果你已經正確設置你的委託並告訴位置經理找到你的位置。如果您假定這個應用程序運行的每個設備在視圖出現5秒後都會有一個位置,那麼它肯定會對某些用戶造成不良影響。 – Craig