Created
April 21, 2018 12:39
-
-
Save PattyAppier/5d57f97e9afa47cfd0e820529101ea38 to your computer and use it in GitHub Desktop.
PattysLucky7App-PattysMapViewController-0421_2018.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
// 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