9

次を使用して現在の場所にズームするmapViewがありますviewDidLoad

#define METERS_PER_MILE 1609.344

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];

    mapView.showsUserLocation=TRUE;

    // zoom to  a specific area
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = -28.994167;
    zoomLocation.longitude = 134.866944;

    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 1900*METERS_PER_MILE, 1900*METERS_PER_MILE);
    MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];    

    // make sure the Google water mark is always visible
    mapView.autoresizingMask =
    (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

    [mapView setRegion:adjustedRegion animated:YES];        

    mapView.delegate=self;

    searchBar.delegate = self;
}

これはうまくいきます。検索バーと特定のアドレスの場所にジャンプする機能を追加しました。これもうまくいきます。現在の場所に戻るボタンを追加したいと思います。手を貸してくれませんか?

乾杯

4

5 に答える 5

11

そのボタンをタップして、マップの中心を現在の場所に設定する必要があります。次のように言います。

- (IBAction)showCurrentLocation {        
    [mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
}
于 2011-08-11T06:35:49.693 に答える
2

あなたも試すことができます:

mapView.userTrackingMode=YES;
mapView.userTrackingMode=NO;
于 2013-02-03T10:55:49.097 に答える
0
- (void)showCurrentLocation{

    MKMapPoint annotationPoint = MKMapPointForCoordinate(self.mapView.userLocation.coordinate);
    MKMapRect zoomRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.0, 0.0);
    [self.mapView setVisibleMapRect:zoomRect animated:YES];
}
于 2014-07-27T12:54:13.483 に答える