Sunday 25 June 2017

Mapkit : Place Annotation(Marker) to Map


STEP -1 : Add 'Map Kit View' to Main.Storyboard

Goto 'Show Object Library' -> Search 'Map Kit View'.

STEP - 2 : ViewController.swift

//
//  ViewController.swift
//  MapTwo
//
//  Created by Admin on 04/04/1939 Saka.
//  Copyright © 1939 Saka Admin. All rights reserved.
//

import UIKit
import MapKit

class ViewController: UIViewController {

    
    @IBOutlet weak var map: MKMapView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let span : MKCoordinateSpan = MKCoordinateSpanMake(0.1, 0.1)
        let location : CLLocationCoordinate2D = CLLocationCoordinate2DMake(22.256412, 77.251032)
        let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
        map.setRegion(region, animated: true)
        let annotation = MKPointAnnotation()
        annotation.coordinate = location
        annotation.title = "My WorkPlace"
        annotation.subtitle = "Enjoy YOUR WORK"
        
        map.addAnnotation(annotation)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

No comments:

Post a Comment