Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PattyAppier/5d57f97e9afa47cfd0e820529101ea38 to your computer and use it in GitHub Desktop.
Save PattyAppier/5d57f97e9afa47cfd0e820529101ea38 to your computer and use it in GitHub Desktop.
PattysLucky7App-PattysMapViewController-0421_2018.md
```
// PattysMapViewController.swift
// PattysMapApp2018
// Created by sendbest on 2018/4/21.
// Copyright © 2018年 sendbest. All rights reserved.
import UIKit
import MapKit // 0421 to import framework.
class PattysMapViewController: UIViewController {
// 0421 to declare the var of mapView and luckySeven.
@IBOutlet var pattysMapView: MKMapView! // 0421 this outlay var named "pattysMapView" is set to connect with Pattys Map Viw.
var luckySeven: ViewController!
// 0421 to add code for add remark in Map.
// to transfer addr to coordinat, and pin it in the Map.
// to add code in ViewDidLoad Func.
override func viewDidLoad() {
super.viewDidLoad()
let geoCoder = CLGeocoder()
// add if-statment
geoCoder.geocodeAddressString(luckySeven.location, completionHandler: { placemarks, error in
if error != nil {
print(error)
return
}
if let placemarks = placemarks {
// retreival of 1st map target spot
let placemark = placemarks[0]
// add anotation
let annotation = MKPointAnnotation()
annotation.title = self.luckySeven.name
annotation.subtitle = self.luckySeven.type
if let location = placemark.location {
annotation.coordinate = location.coordinate
// show the pin
self.pattysMapView.showAnnotations([annotation], animated: true)
self.pattysMapView.selectAnnotation(annotation, animated: true)
}
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment