0

cllocationmanager を使用して現在の場所を取得しようとしています。

問題:

デリゲート メソッド

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

ビューdidappearの後に常に実行されます。viewDidLoadでstartupdatingLocation. そして、viewdidLoad の最後でメソッド SetMapView を呼び出します。

-(void)setMapView{

MKCoordinateRegion zoomIn = plotsMapView.region;
zoomIn.span.latitudeDelta  = 0.2;
zoomIn.span.longitudeDelta  = 0.2;



zoomIn.center.latitude =  self.currentLocation.coordinate.latitude;//[[[m_CityMarkerArray objectAtIndex:0] valueForKey:@"lat"] doubleValue];
zoomIn.center.longitude = self.currentLocation.coordinate.longitude;//[[[m_CityMarkerArray objectAtIndex:0] valueForKey:@"lng"] doubleValue];



NSLog(@"%f LAT",self.currentLocation.coordinate.latitude);

[plotsMapView setRegion:zoomIn animated:YES];



}

LAT は 0.0000 が返されます。

しかし、viewDidAppear で同じメソッドを呼び出すと、正常に動作します。また、viewDidAppear でメソッドを呼び出すと、view.I に戻るたびにマップをベースの場所にリロードするため、viewdidload でそれが必要です。

助けてください!ありがとう!

4

1 に答える 1

1

ロケーション マネージャー デリゲートをselfに設定し、.h ファイルにCLLocationManagerDelegateを追加した場合は、 didUpdateToLocationメソッド内でsetMapViewメソッドを呼び出します。didUpdateToLocation 内で、setMapView メソッドを呼び出す前に、newLocation 座標を currentLocation 座標に割り当てます。

于 2012-09-05T15:13:51.630 に答える