我尝试从不同的按钮方法向地图添加注释,但它并没有显示出来。它也没有给出错误。
我在mapView方法中提到的所有注释都在显示。
-(void) testButton {
/// custom location coordinate
CLLocationCoordinate2D userLocationNew2 = CLLocationCoordinate2DMake(-80.050003, -13.416667);
// use that cusom coordinate
MKCoordinateRegion region2 = MKCoordinateRegionMakeWithDistance(userLocationNew2, 20000, 20000);
[mapView setRegion:[self.mapView regionThatFits:region2] animated:YES];
// Add an annotation
MKPointAnnotation *point2 = [[MKPointAnnotation alloc] init];
point2.coordinate = userLocationNew2;
point2.title = @"Check";
// point2.subtitle = @"Right here oooooo!!!";
[mapView addAnnotation:point2];
}
另一种方法
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
/// custom location coordinate
CLLocationCoordinate2D userLocationNew2 = CLLocationCoordinate2DMake(-73.050003, -13.416667);
// use that cusom coordinate
MKCoordinateRegion region2 = MKCoordinateRegionMakeWithDistance(userLocationNew2, 20000, 20000);
[self.mapView setRegion:[self.mapView regionThatFits:region2] animated:YES];
// Add an annotation
MKPointAnnotation *point2 = [[MKPointAnnotation alloc] init];
point2.coordinate = userLocationNew2;
point2.title = @"Basic";
}