STEP - 1 : Add a button to Main.Storyboard
STEP - 2 : ViewController.swift
//
// ViewController.swift
// Map
//
// Created by Admin on 04/04/1939 Saka.
// Copyright © 1939 Saka Admin. All rights reserved.
//
import UIKit
import MapKit
class ViewController: UIViewController {
@IBAction func showMeWhere(_ sender: Any) {
let latitude : CLLocationDegrees = 28.441830
let longitude : CLLocationDegrees = 76.258830
let regionDistance : CLLocationDistance = 1000;
let coordinate = CLLocationCoordinate2DMake(latitude, longitude)
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinate, regionDistance, regionDistance)
let options = [MKLaunchOptionsMapCenterKey : NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey : NSValue(mkCoordinateSpan : regionSpan.span)]
let placemark = MKPlacemark(coordinate: coordinate)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = "My House"
mapItem.openInMaps(launchOptions: options)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
STEP - 3 : Run the app and press on 'Click Me Where' button
No comments:
Post a Comment