简体   繁体   English

MapView显示图钉位置,然后消失

[英]MapView shows pin location and then disappears

I've never used the Map-view before, and I was following this tutorial 我以前从未使用过Map-view,并且正在关注教程

At the very end, my simulator shows the point the way it is supposed to, in the location it is supposed to, but then immediately changes to a blue screen. 最后,我的模拟器在预期的位置显示了预期的方式,但随后立即变为蓝屏。

the blue screen is still in Google maps (It shows the Google logo at the bottom) but it is no longer what I am trying to show. 蓝屏仍在Google地图中(它在底部显示Google徽标),但不再是我要显示的内容。

首先看起来像这样片刻之后看起来像这样

Here is some of my code: 这是我的一些代码:

- (void)viewDidLoad 
{
    HandbookAppDelegate *delegate = (HandbookAppDelegate *)[[UIApplication sharedApplication] delegate];
    Rule *thisRule = [delegate.rules objectAtIndex:index.row];

    self.title = thisRule.ruleNumber;

    // Set some coordinates for our position (Buckingham Palace!)
    CLLocationCoordinate2D location;
    location.latitude = (double) 51.501468;
    location.longitude = (double) -0.141596;

    // Add the annotation to our map view
    MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location];
    [self.map addAnnotation:newAnnotation];
    [newAnnotation release];
}

- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id <MKAnnotation> mp = [annotationView annotation];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
    [mv setRegion:region animated:YES];
    [mv selectAnnotation:mp animated:YES];
}

I was able to discover the solution on my own. 我能够自己找到解决方案。 Turns out it was rather silly. 事实证明这很愚蠢。

I had turned on "shows user location" on the xib for my MKMapView, so that was interfering. 我已经在MIBMapView的xib上打开了“显示用户位置”,这很干扰。 When I turned it off, the problem went away. 当我关闭它时,问题就消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM