I'm trying to add a search bar to my map programatically, and have established that I need to add a navigation controller to my map view in order to format the search bar correctly at the top of the view. I have come to the conclusion I actually need a UISearchController, rather than a UI SearchBar. However, I do not have a navigation controller coded into the app from the AppDelegate file because I am also using a tabBarController, which is coded in the app delegate.
Basically, I'm looking for a way to embed a UINavigationController into my map view programatically so I can add the UISearchController to the NavigationController.
The ultimate goal is to create a map with a search feature to allow users to search for locations - if anyone has other suggestions of how I can accomplish this goal within the framework I already have it would be much appreciated!
My AppDelegate and map view code are below.
AppDelegate
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = TabBarController()
return true
}
}
MapViewController
import UIKit
import MapKit
import CoreLocation
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var mapVw: MKMapView!
let locationManager = CLLocationManager()
var regionHasBeenCentered = false
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
if !regionHasBeenCentered {
let span: MKCoordinateSpan = MKCoordinateSpanMake(0.5, 0.5)
let userLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region: MKCoordinateRegion = MKCoordinateRegionMake(userLocation, span)
mapVw.setRegion(region, animated: true)
regionHasBeenCentered = true
}
self.mapVw.showsUserLocation = true
}
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
setupMapView()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
func setupMapView() {
mapVw = MKMapView()
mapVw.delegate = self
let leftMargin:CGFloat = 0
let topMargin:CGFloat = 0
let mapWidth:CGFloat = view.frame.size.width
let mapHeight:CGFloat = view.frame.size.height
mapVw.frame = CGRect(x: leftMargin, y: topMargin, width: mapWidth, height: mapHeight)
let noLocation = self.mapVw.userLocation.coordinate
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.05, 0.05)
let pinLocation = MKCoordinateRegionMake(noLocation, span)
mapVw.setRegion(pinLocation, animated: true)
print(pinLocation)
print(noLocation)
//setup long press gesture
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(self.addAnnotation(_:)))
self.mapVw.addGestureRecognizer(longPress)
view.addSubview(mapVw)
}
#objc func addAnnotation(_ gestureRecognizer:UIGestureRecognizer) {
if gestureRecognizer.state != UIGestureRecognizerState.began {
return
}
let touchPoint = gestureRecognizer.location(in: self.mapVw)
let newCoordinates = self.mapVw.convert(touchPoint, toCoordinateFrom: self.mapVw)
let annotation = MKPointAnnotation()
annotation.coordinate = newCoordinates
annotation.title = "Virtual Location"
annotation.subtitle = "Dropped Pin"
self.mapVw.removeAnnotations(mapVw.annotations)//remove previous pin
self.mapVw.removeAnnotation(annotation)
//create circle attributes
let cent = newCoordinates
let rad: Double = 500 //adjust radius to make circle bigger.
let circle = MKCircle(center: cent, radius: rad)
self.mapVw.addAnnotation(annotation)
self.mapVw.removeOverlays(self.mapVw.overlays)//remove previous circle
self.mapVw.add(circle)
print(newCoordinates)
print(circle)
}
//circle overlay function
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay.isKind(of: MKCircle.self){
let circleRenderer = MKCircleRenderer(overlay: overlay)
circleRenderer.fillColor = UIColor.blue.withAlphaComponent(0.05)
circleRenderer.strokeColor = UIColor.blue
circleRenderer.lineWidth = 0.5
return circleRenderer
}
self.mapVw.removeOverlays(overlay as! [MKCircle])
print(overlay)
return MKOverlayRenderer(overlay: overlay)
}
}
TabBarController
import UIKit
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let messagesController = MessagesController()
let messagesNavController = UINavigationController(rootViewController: MessagesController())
messagesNavController.tabBarItem.title = "Messages"
let postsVC = PostsViewController()
postsVC.tabBarItem.title = "Posts"
let organiserVC = OrganiserViewController()
organiserVC.tabBarItem.title = "Organiser"
let mapVC = MapViewController()
mapVC.tabBarItem.title = "Map"
let mapNavigationController = UINavigationController(rootViewController: mapVC)
viewControllers = [messagesNavController, postsVC, organiserVC, mapVC]
}
}
Related
Here is the problem. In my view controller, I have placed a segmented control on the top.
On controller load it displays the map, circle and the marker. Now, when I click the segmented control to change the map type it goes into the code block on select but never updates the Map type.
Please see the code here.
class MapController: UIViewController, CLLocationManagerDelegate , GMSMapViewDelegate {
var locationManager:CLLocationManager!
let marker = GMSMarker()
var roundCircle: GMSCircle!
var mapView = GMSMapView()
private var didPerformGeocode = false
enum maptype:NSInteger
{
case standardmap = 0
case satellitemap = 1
}
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func segmentedControlAction(_ sender: UISegmentedControl)
{
switch sender.selectedSegmentIndex {
case maptype.standardmap.rawValue:
mapView.mapType = .normal
**no change in the map type**
case maptype.satellitemap.rawValue:
mapView.mapType = .satellite
**no change in the map type**
default:
break
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
determineMyCurrentLocation()
}
func determineMyCurrentLocation() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation
guard !didPerformGeocode else { return }
didPerformGeocode = true
locationManager.stopUpdatingLocation()
let camera = GMSCameraPosition.camera(withLatitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude, zoom: 13.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.delegate = self
self.view = mapView
let markerImage = UIImage(named: "mapMarker")!.withRenderingMode(.alwaysTemplate)
let markerView = UIImageView(image: markerImage)
markerView.tintColor = UIColor.red
marker.iconView = markerView
marker.position = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)
marker.map = mapView
roundCircle = GMSCircle(position: camera.target, radius: 1500) //0.96 Miles
roundCircle.fillColor = UIColor.red.withAlphaComponent(0.3)
roundCircle.strokeColor = nil
roundCircle.map = mapView
}
}
Honestly, I don't use Google Maps
However, to change MapTypes in Apple Maps I use
#IBAction func Whatever(_ sender: UISegmentedControl) {
mapView.mapType = MKMapType.init(rawValue: UInt(sender.selectedSegmentIndex)) ?? .normal
}
Maybe it will work
In Appleās iOS Reminders app, you can set a location area at which you would be reminded of your reminder. When you set the location area, you are allowed to draw a circle that covers the area of the location you want to be reminded at. How would I duplicate this feature. I particularly would like to know how to allow the user to resize the circle on a map view by dragging his finger on the edge of the circle. I have already figured out how to create the circle.
Here is my code so far:
import UIKit
import MapKit
class ViewController: UIViewController {
// MARK: - Outlets
#IBOutlet weak var mapView: MKMapView!
// MARK: - Variables and Constants
let regionRadius: CLLocationDistance = 1000
let circularRegionRadius: CLLocationDistance = 500
let locationManager = CLLocationManager()
// MARK: - View
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
centerMapOnLocation(location: locationManager.location!)
}
// MARK: - Actions
#IBAction func addRegion(_ sender: UILongPressGestureRecognizer) {
print("addRegion(_:)")
let longPress = sender
let touchLocation = longPress.location(in: mapView)
let coordinates = mapView.convert(touchLocation, toCoordinateFrom: mapView)
let region = CLCircularRegion(center: coordinates, radius: circularRegionRadius, identifier: "geofence")
mapView.removeOverlays(mapView.overlays)
locationManager.startMonitoring(for: region)
let circle = MKCircle(center: coordinates, radius: region.radius)
mapView.add(circle)
}
// MARK: - Helper Functions
func centerMapOnLocation(location: CLLocation) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
regionRadius, regionRadius)
mapView.setRegion(coordinateRegion, animated: true)
}
// MARK: - Memory Warning
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
print("mapView(_:rendererFor:_:)")
guard let circelOverLay = overlay as? MKCircle else {return MKOverlayRenderer()}
let circleRenderer = MKCircleRenderer(circle: circelOverLay)
circleRenderer.strokeColor = .blue
circleRenderer.fillColor = .blue
circleRenderer.alpha = 0.2
return circleRenderer
}
}
extension ViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("locationManager(_:didUpdateLocations:)")
locationManager.stopUpdatingLocation()
mapView.showsUserLocation = true
}
}
I am facing a weird issue while using GoogleMapsSDK. On my view that is showing the Google Map, a navigation controller is embedded. On the nav bar, I have a bar button that I have connected to a new view. When the button is pressed, the segue is laggy and doesn't show any content.
Here is what is happening: http://gph.is/2putLtQ
Not sure what the issue is. I have the same set up working without GoogleMapsSDK implemented.
Here is the GoogleMaps view controller:
import UIKit
import GoogleMaps
class GoogleMapsViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate {
var locationManager = CLLocationManager()
var tacoLocations = [TacoLocation]()
var tacoLocationPlace_id :String!
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager = CLLocationManager()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.distanceFilter = kCLDistanceFilterNone
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
let lat = self.locationManager.location?.coordinate.latitude
let lng = self.locationManager.location?.coordinate.longitude
// creates the map and zooms the current user location, at a 15.0 zoom
let camera = GMSCameraPosition.camera(withLatitude: lat!, longitude: lng!, zoom: 15.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView
for location in self.tacoLocations {
let marker = GMSMarker()
let lat = location.locationLat
let lng = location.locationLng
marker.position = CLLocationCoordinate2D(latitude: lat!, longitude: lng!)
marker.title = location.name
if location.open_now == false {
marker.snippet = "\(location.vicinity!)\nClosed"
} else if location.open_now == true {
marker.snippet = "\(location.vicinity!)\nOpen"
} else {
}
marker.userData = location
marker.icon = UIImage(named: "taco_marker.png")
marker.infoWindowAnchor = CGPoint(x: 0.5, y: 0.2)
marker.map = mapView
}
// enable my location dot
mapView.isMyLocationEnabled = true
mapView.delegate = self
}
//MARK: GMSMapViewDelegate
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
let customWindow = Bundle.main.loadNibNamed("CustomInfoWindow", owner: self, options: nil)?.first as! CustomInfoWindow
customWindow.nameLabel.text = marker.title
customWindow.addressLabel.text = marker.snippet
return customWindow
}
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
let tacoLocation = marker.userData as! TacoLocation
self.tacoLocationPlace_id = tacoLocation.place_id
DispatchQueue.main.async {
self.performSegue(withIdentifier: "MoreInfoSegue", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "MoreInfoSegue" {
let tabVC = segue.destination as! UITabBarController
let moreInfoVC = tabVC.viewControllers?[0] as! MoreInfoViewController
let reviewVC = tabVC.viewControllers?[1] as! ReviewViewController
moreInfoVC.tacoLocationPlace_id = self.tacoLocationPlace_id
reviewVC.tacoLocationPlace_id = self.tacoLocationPlace_id
} else if segue.identifier == "ARSegue" {
//segue to new view that is not working correctly.
}
}
}
The only thing in the second view controller is the viewdidload.
Any help is much appreciated!
I uninstalled the google maps pods and then reinstalled them. That fixed my issue. Must have been a bug with xcode.
In my app the user can search for a location and it adds a pin. I want a next button to go to another view controller and show the exact same map but in a smaller version. How can I move the exact same map to another view controller?
import UIKit
import MapKit
protocol HandleMapSearch {
func dropPinZoomIn(placemark:MKPlacemark)
}
class ViewController: UIViewController {
let locationManager = CLLocationManager()
var resultSearchController:UISearchController? = nil
var selectedPin:MKPlacemark? = nil
#IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()
//
let locationSearchTable = storyboard!.instantiateViewControllerWithIdentifier("LocationSearchTable") as! LocationSearchTable
resultSearchController = UISearchController(searchResultsController: locationSearchTable)
resultSearchController?.searchResultsUpdater = locationSearchTable
//
let searchBar = resultSearchController!.searchBar
searchBar.sizeToFit()
searchBar.placeholder = "Search for places"
navigationItem.titleView = resultSearchController?.searchBar
//
resultSearchController?.hidesNavigationBarDuringPresentation = false
resultSearchController?.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
//
locationSearchTable.mapView = mapView
//
locationSearchTable.handleMapSearchDelegate = self
//
let button = UIButton(type: UIButtonType.System) as UIButton
button.frame = CGRectMake(100, 100, 100, 50)
button.backgroundColor = UIColor.greenColor()
button.setTitle("Button", forState: UIControlState.Normal)
button.addTarget(self, action: Selector("Action:"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController : CLLocationManagerDelegate {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedWhenInUse {
locationManager.requestLocation()
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: location.coordinate, span: span)
mapView.setRegion(region, animated: true)
}
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("error:: \(error)")
}
}
extension ViewController: HandleMapSearch {
func dropPinZoomIn(placemark:MKPlacemark){
// cache the pin
selectedPin = placemark
// clear existing pins
mapView.removeAnnotations(mapView.annotations)
let annotation = MKPointAnnotation()
annotation.coordinate = placemark.coordinate
annotation.title = placemark.name
if let city = placemark.locality,
let state = placemark.administrativeArea {
annotation.subtitle = "\(city) \(state)"
}
mapView.addAnnotation(annotation)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegionMake(placemark.coordinate, span)
mapView.setRegion(region, animated: true)
}
}
extension ViewController : MKMapViewDelegate {
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView?.pinTintColor = UIColor.orangeColor()
pinView?.canShowCallout = true
pinView?.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIButton
return pinView
}
func mapView(mapView: MKMapView, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == annotationView.rightCalloutAccessoryView {
print("Disclosure Pressed!")
}
}
}
you can pass annotation or lat long to another view controller while performing segue or push new controller. If you are using segue then you can use prepare for segue method.
Second thing you can make a custom class for mapview. and can put some properties in it like annotation or lat long then create object of this class and set this property so according that properties this class return map view (make method accordingly). you can use class in many viewcontroller not only in just two.
Update as per comment :
refer this link to know how to push new view controller.
and refer this storyboard segue tutorial. Actually it concepts and not possible to explain here everything if you have some error in code then i can solve here but for learn whole concepts you should follows different tutorials and notes. do research. google it you will find many links.
hope this will help :)
I've been trying to code in swift a prepare for segue or to push view controller in order to move a map with a pin i have in a View Controller to another View Controller but in a smaller version. If someone can give an example on how to do it with this code, you would be very helpful.
I've been trying to do this in this function, so that when the user clears the pin title it goes to the other view controller with that same map:
if control == annotationView.rightCalloutAccessoryView {
print("Disclosure Pressed!")
}
Here's the complete code for this View Controller.
import UIKit
import MapKit
protocol HandleMapSearch {
func dropPinZoomIn(placemark:MKPlacemark)
}
class ViewController: UIViewController {
let locationManager = CLLocationManager()
var resultSearchController:UISearchController? = nil
var selectedPin:MKPlacemark? = nil
#IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()
//
let locationSearchTable = storyboard!.instantiateViewControllerWithIdentifier("LocationSearchTable") as! LocationSearchTable
resultSearchController = UISearchController(searchResultsController: locationSearchTable)
resultSearchController?.searchResultsUpdater = locationSearchTable
//
let searchBar = resultSearchController!.searchBar
searchBar.sizeToFit()
searchBar.placeholder = "Search for places"
navigationItem.titleView = resultSearchController?.searchBar
//
resultSearchController?.hidesNavigationBarDuringPresentation = false
resultSearchController?.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
//
locationSearchTable.mapView = mapView
//
locationSearchTable.handleMapSearchDelegate = self
//
let button = UIButton(type: UIButtonType.System) as UIButton
button.frame = CGRectMake(100, 100, 100, 50)
button.backgroundColor = UIColor.greenColor()
button.setTitle("Button", forState: UIControlState.Normal)
button.addTarget(self, action: Selector("Action:"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController : CLLocationManagerDelegate {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedWhenInUse {
locationManager.requestLocation()
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: location.coordinate, span: span)
mapView.setRegion(region, animated: true)
}
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("error:: \(error)")
}
}
extension ViewController: HandleMapSearch {
func dropPinZoomIn(placemark:MKPlacemark){
// cache the pin
selectedPin = placemark
// clear existing pins
mapView.removeAnnotations(mapView.annotations)
let annotation = MKPointAnnotation()
annotation.coordinate = placemark.coordinate
annotation.title = placemark.name
if let city = placemark.locality,
let state = placemark.administrativeArea {
annotation.subtitle = "\(city) \(state)"
}
mapView.addAnnotation(annotation)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegionMake(placemark.coordinate, span)
mapView.setRegion(region, animated: true)
}
}
extension ViewController : MKMapViewDelegate {
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView?.pinTintColor = UIColor.orangeColor()
pinView?.canShowCallout = true
pinView?.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIButton
return pinView
}
func mapView(mapView: MKMapView, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == annotationView.rightCalloutAccessoryView {
print("Disclosure Pressed!")
}
}
}
In a word, no. Don't do that.
Trying to move views between view controllers is almost certainly the wrong way to do things.
It absolutely will not work to move a view (including a map view) from one view controller to another in prepareForSegue. The destination view controller's views haven't been loaded when prepareForSegue is called.
Instead, if you want to show a map in both your current view controller and the one to which you are segueing, you should define a map view in both view controllers, sized the way you want them in both places. You can then use prepareForSegue to tell the destination view controller the map region to display in it's map view. (Don't try to manipulate the destination view controller's map view from prepareForSegue. It won't work, and it's bad design even if you could make it work.)
Add a property mapRegion of type MKCoordinateRegion to the destination view controller. In the source view controller's prepareForSegue, get the map region of the current map and set the destination view controller's mapRegion property using that value.
Then, in the destination view controller's viewWillAppear:animated method, take the mapRegion property and used it to set the map view's region.
EDIT:
You also mentioned a pin. If you want the same pin to appear in both maps you should be able to fetch the MKAnnotation from the source view controller's map and pass it to the destination view controller, much like I described for setting the map region.