1

iOS 6 MKMap ビューを使用するアプリケーションを開発しています。「ユーザー位置ボタン」(マップ アプリケーションを使用しているときに画面の左下に表示されるボタン) を有効にしたいと考えています。私を助けることができるものは何も見つからなかったので、このコードでこのボタンを自分で作成しようとしました:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    CLLocationCoordinate2D currentCoordinates;
    currentCoordinates.latitude = newLocation.coordinate.latitude;
    currentCoordinates.longitude = newLocation.coordinate.longitude;

    MKCoordinateRegion viewRegion = MKCoordinateRegionMake(currentCoordinates, _mapView.region.span);
    [_mapView setRegion:viewRegion animated:YES];
    [locationManager stopUpdatingLocation];

}

- (IBAction)moveToCurrentLocation:(id)sender {
        [locationManager startUpdatingLocation];
}

そのため、ボタンを押すと、locationManager がユーザーの現在の場所を更新し、マップがユーザーの現在の場所を中心とした同じ範囲の新しいリージョンに変更されます。ここで別の問題があります。ボタンを押すと、マップは正しい座標に移動しますが、古いスパンで新しいリージョンを作成してもズームアウトします (つまり、スパンが増加します)。この動作が理解できません。マップ アプリと同じように、古いスパンを保持したいと考えています。

4

2 に答える 2

0

マップ上のそのボタンはuserTrackingMode、mapView のプロパティを切り替えているため、次のいずれかに設定します。

MKUserTrackingModeNone //nothing, normal map view
MKUserTrackingModeFollow //user is highlighted and stays centered on map when you move
MKUserTrackingModeFollowWithHeading //you get the heading as well, so your direction is up on the map
于 2013-07-06T08:51:15.500 に答える
0

そのために公式のiOSボタンを使用したい場合、このコードはそれをUIToolbarに追加し、マップビューに接続します

UIBarButtonItem *trackingButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView];
NSMutableArray *items = [[NSMutableArray alloc] initWithArray:self.toolbar.items];
[items addObject:trackingButton];
[self.toolbar setItems:items];
于 2013-07-06T10:50:52.653 に答える