Hello,
I am creating feature on my app that is supposed to launch the iOS map and who a destination using coordinates given from Firebase. I keep getting errors as shown in this video and here is the project:
//
// ViewController.swift
// Launch Map Button
//
// Created by Gilbert Emuge on 8/24/21.
//
import UIKit
import MapKit
import FirebaseDatabase
class ViewController: UIViewController {
// Launch map
@IBAction func showMeWhere(_ sender: Any)
{
//Defining destination
let ref = Database.database().reference()
ref.child("location").observeSingleEvent(of: .value) {
(snapshot) in
let latitude = snapshot.value
let longitude = snapshot.value
let regionDistance: CLLocationDistance = 1000.0;
let coordinates = CLLocationCoordinate2DMake(latitude as! CLLocationDegrees, longitude as! CLLocationDegrees)
let regionSpan = MKCoordinateRegion(center: coordinates, latitudinalMeters: regionDistance, longitudinalMeters: regionDistance)
let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)]
let placemark = MKPlacemark(coordinate: coordinates)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = "Destination"
mapItem.openInMaps(launchOptions: options)
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
/*
@IBAction func showMeWhere(_ sender: Any)
{
//Defining destination
let latitude:CLLocationDegrees = 38.791794
let longitude:CLLocationDegrees = -90.563419
let regionDistance: CLLocationDistance = 1000;
let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
let regionSpan = MKCoordinateRegion(center: coordinates, latitudinalMeters: regionDistance, longitudinalMeters: regionDistance)
let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)]
let placemark = MKPlacemark(coordinate: coordinates)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = "Destination"
mapItem.openInMaps(launchOptions: options)
}
*/