Вы должны передать адрес места проведения также с лат-длинной:
import UIKit
import MapKit
func openMapForPlace() {
let lat1 : NSString = self.venueLat
let lng1 : NSString = self.venueLng
let latitude:CLLocationDegrees = lat1.doubleValue
let longitude:CLLocationDegrees = lng1.doubleValue
let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
let address = [CNPostalAddressStreetKey: address ?? "",
CNPostalAddressCityKey: city ?? "",
CNPostalAddressStateKey: state ?? "",
CNPostalAddressPostalCodeKey: zipCode,
CNPostalAddressISOCountryCodeKey: isoCountryCodeKey ?? ""]
let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: address)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = "\(self.venueName)"
let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
mapItem.openInMaps(launchOptions: launchOptions)
}
В swift
код будет ниже:
import UIKit
import MapKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
openMapForPlace()
}
func openMapForPlace() {
let latitude: CLLocationDegrees = 39.9517958
let longitude: CLLocationDegrees = -75.1611398
let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
let address = [CNPostalAddressStreetKey: "1234 Market St",
CNPostalAddressCityKey: "Philadelphia",
CNPostalAddressStateKey: "Pennsylvania",
CNPostalAddressPostalCodeKey: "19107",
CNPostalAddressISOCountryCodeKey: "USA"]
let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: address)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = "1234 Market St, Philadelphia, Pennsylvania, 19107"
let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
mapItem.openInMaps(launchOptions: launchOptions)
}
}