I have two view controllers, MapViewVC
and MapDetailViewVC
.
I have several custom pin annotations on the MapView
.
When tapped, these annotations (with a certain default "altitude" view) initiate a the MapDetailVC
that shows a snapshot of the annotation with the camera property set to a definite altitude (4000 m).
As a result, when the "back" button is pressed on the MapDetailVC
, the view goes back to the MapViewVC
with same altitude as was presented in the MapDetailVC
; not to the original altitude which was simply the area being viewed at the time the callout button was tapped.
I want to know (from those more experienced with MapKit
) if there is a way to set the mapView
back to its original setting when the "back" button is tapped.
Thanks
MapDetailViewController *mapDetail = [[self storyboard]
instantiateViewControllerWithIdentifier:@"MapDetailViewController"];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Map"
style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
Word *word = [[Word alloc] init];
word.name = biblicalPin.title;
MKMapCamera *myCamera = [MKMapCamera
cameraLookingAtCenterCoordinate:biblicalPin.coordinate
fromEyeCoordinate:biblicalPin.coordinate
eyeAltitude:2000];
mapView.camera = myCamera;
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
options.size = CGSizeMake(320, 140);
options.camera = myCamera;
options.scale = [[UIScreen mainScreen] scale];
options.region = self.mapView.region;
options.mapType = MKMapTypeSatellite;
MKMapSnapshotter *snapshotter =
[[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *e)
{
//if (e) ...;// Handle errors
UIImage *image = snapshot.image;
mapDetail.imageView.image = image;
mapDetail.currentWordDetail = word;
mapDetail.locationLabel.text = biblicalPin.title;
mapDetail.locationDescription.text = biblicalPin.information;
//[backButton --- add a method to return the user to the original mapView alititude.
}];
word.definition = biblicalPin.information;
[self.navigationController pushViewController:mapDetail animated:YES];
One way to reset map is call delegate method when back button is pressed.
Create delegate method in
MapDetailVC
like:Make delegate self when you create view controller object in
MapViewVC
controller class. Also extend extendMapViewVC
class interface with delegate<MapDetailDelegate>
Create method
-resetMapView()
inMapViewVC
class.Now when back button is pressed call this method from
MapDetailVC
controller class usingdelegate
object.Edit:
The flow for reset map here will be same for your need. Now instead of getting user location you can call below method in
-resetMapView()
to load default camera zoom.Above code is taken from this answer