1

我刚开始使用 MapKit 框架,我的第一次实践并不顺利 :)

一切似乎都很好,除了 MapView 显示在海洋中的某个地方并且它没有找到任何地方(例如:陆地、岛屿)。我认为纬度和经度不知何故超出了范围。

这是我的代码:

    - (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];
}
4

1 回答 1

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];
...
于 2013-03-18T15:22:01.407 回答