2010年3月24日水曜日

MKMapViewにCLLocationManagerを使って今いる場所を表示する

忘れそうなので。


表示時に、

CLLocationManager *manager = [[CLLocationManager alloc] init];
manager.desiredAccuracy = kCLLocationAccuracyBest;
manager.distanceFilter = kCLDistanceFilterNone;
manager.delegate = self;
[manager startUpdatingLocation];


で、delegate。

- (void) locationManager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation{
MKCoordinateRegion zoom = mapView.region;
zoom.span.latitudeDelta = 0.005;
zoom.span.longitudeDelta = 0.005;
zoom.center = newLocation.coordinate;
[mapView setRegion: zoom animated: YES];
}


0 件のコメント: