I have this code that I need altered slightly. The code I have below creates a pin on my current location (perfectly as I might add).
The only problem is that I need the code only to be run when I click a button, not every time I move.
Here is the code of the current location and the pin.
- (void)viewDidLoad {
[super viewDidLoad];
[self.mapView setDelegate:self];
[self.mapView setShowsUserLocation:YES];
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
// zoom to region containing the user location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 700, 700);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
// add the annotation
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = userLocation.coordinate;
point.title = @"Your Car";
//point.subtitle = @"";
[self.mapView addAnnotation:point];
}
I need this to run when I click a button such as:
-(IBAction)addPin
{
}
In the viewDidLoad: method,
Create a button like this:
// create the method defined as selector method for the UIButton in your viewcontroller