简体   繁体   中英

MapView shows pin location and then disappears

I've never used the Map-view before, and I was following this tutorial

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.

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

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. When I turned it off, the problem went away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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