我有一个问题。关于同样的问题,我一直在寻找关于堆栈溢出的其他答案,我无法让它为我工作。所以我打算在这里问一下。我想要做的是当我在地图视图上并获得我想要自动缩放到该位置的用户位置时。
h-file
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface WalkingTableViewController: UIViewController <MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *MKMapView;
@end
m-file
#import "WalkingTableViewController.h"
@interface UITableViewController ()
@end
@implementation WalkingTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.MKMapView.showsUserLocation=YES;
self.MKMapView.delegate = self;
[self.MKMapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
}
- (IBAction)StopButton:(id)sender
- (IBAction)StartButton:(id)sender
@end
答案 0 :(得分:1)
如果您希望看到缩放动画,我会将代码放在viewDidAppear方法中,以便在显示视图控制器后动画启动。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CLLocationManager* tempLocationManager = [[CLLocationManager alloc] init];
MKCoordinateRegion tRegion = MKCoordinateRegionMakeWithDistance([tempLocationManager.location coordinate], 20000, 20000);
[self.MKMapView setRegion:tRegion animated:animated];
}
根据需要调整区域(缩放级别,上例中为20000)。
答案 1 :(得分:0)
您需要做的是告诉mapview放大一个区域。这应该让你开始:
CLLocationCoordinate2D center = _mapView.userLocation.coordinate;
MKCoordinateRegion region = MKCoordinateRegionMake(center, MKCoordinateSpanMake(2000, 2000));
[_mapView setRegion:region animated:YES];