I am trying to create a view for in my app which shows the location of a restaurant. When the user enters the view, it shows something like this 
But instead shows the location of the restaurant with a pin and a more zoomed in view. I am new to MapKit and have not been able to make any progress.
This is what my view consists of.

And this is what my view controller consists of.
import UIKit
import MapKit
class FD1ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
private let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
import UIKit
import MapKit
class FD1ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
//Create the pin location of your restaurant(you need the GPS coordinates for this)
let restaurantLocation = CLLocationCoordinate2D(latitude: 111.0, longitude: 111.0)
//Center the map on the place location
mapView.setCenter(restaurantLocation, animated: true)
}
}
This should do it. I hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With