// ViewController.swift
// MapAnnotation1
import UIKit
import MapKit
class ViewController: UIViewController,MKMapViewDelegate {
@IBOutlet var mpView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.22.992244, 72.632117 22.992659, 72.632138
let span : MKCoordinateSpan = MKCoordinateSpanMake(0.1, 0.1)
let loctaion : CLLocationCoordinate2D = CLLocationCoordinate2DMake(22.992244, 72.632117)
let loctaion1 : CLLocationCoordinate2D = CLLocationCoordinate2DMake(22.992659, 72.632138)
let region : MKCoordinateRegion = MKCoordinateRegionMake(loctaion, span)
mpView.setRegion(region, animated: true)
let annonation = MKPointAnnotation()
annonation.title = "me"
annonation.subtitle = "me here"
annonation.coordinate = loctaion
mpView.addAnnotation(annonation)
let annonation1 = MKPointAnnotation()
annonation1.title = "he"
annonation1.subtitle = "he here"
annonation1.coordinate = loctaion1
mpView.addAnnotation(annonation1)
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView = MKPinAnnotationView()
if annotation.title! == String("me")
{
annotationView.pinTintColor = UIColor.black
return annotationView
}
else
{
annotationView.pinTintColor = UIColor.purple
return annotationView
}
//return annotationView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Comments
Post a Comment