我正在尝试让我的当前位置在mkmapview中自动放大,但我无法让它工作。 这里有一些代码,我想要的是像Runkeeper一样自动缩放。
**the h-file**
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface WalkingTableViewController: UIViewController <MKMapViewDelegate>
@property ( strong, nonatomic) MKMapView *mapView;
@end
**the m-file**
#import "WalkingTableViewController.h"
@interface WalkingTableViewController ()
@end
@implementation WalkingTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.showsUserLocation=YES;
self.mapView.delegate = self;
[self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
// zoom in on users location (?)
}
@end
答案 0 :(得分:0)
您需要设置区域,例如:
MKCoordinateRegion region;
region = MKCoordinateRegionMakeWithDistance(_mapView.userLocation.coordinate,10000,10000);
[_mapView setRegion:region animated:YES];
10000是您想要在地图中看到的中心点的距离。
答案 1 :(得分:0)
这应该像魅力一样
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(your_lat, yout_longitude, 1000.0, 1000.0);
region.span.latitudeDelta = MAX(region.span.latitudeDelta, (coord.latitude - coord.latitude) * 1.05);
region.span.longitudeDelta = MAX(region.span.longitudeDelta, (coord.longitude + coord.longitude) * 1.05);
mapView.region = region;