我刚开始使用MapKit框架,我的第一次练习并不顺利:)
除了MapView显示在海洋的某个地方并且找不到任何地方(例如:Land,island)之外,一切似乎都能正常工作。我认为纬度和经度会以某种方式超出范围。
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIBarButtonItem *zoomButton =
[[UIBarButtonItem alloc]
initWithTitle: @"Zoom-In"
style:UIBarButtonItemStyleBordered
target: self
action:@selector(zoomIn:)];
UIBarButtonItem *typeButton =
[[UIBarButtonItem alloc]
initWithTitle: @"Zoom-Out"
style:UIBarButtonItemStyleBordered
target: self
action:@selector(zoomOut:)];
NSArray *buttons = [[NSArray alloc]
initWithObjects:zoomButton, typeButton, nil];
barButtons.items = buttons;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
zoomLocation.latitude = 48.431638;
zoomLocation.longitude= 27.169436;
annotationPoint.coordinate = zoomLocation;
annotationPoint.title = @"My Company";
annotationPoint.subtitle = @"my Company Title";
//[self __mapView];
MKCoordinateRegion adjustedRegion = [__mapView regionThatFits:viewRegion];
[__mapView setRegion:adjustedRegion animated:YES];
[__mapView addAnnotation:annotationPoint];
}
答案 0 :(得分:2)
您在创建区域后设置zoomLocation
坐标。首先尝试设置zoomLocation
...
zoomLocation.latitude = 48.431638;
zoomLocation.longitude= 27.169436;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
...