Skip to content

Instantly share code, notes, and snippets.

@akio0911
Created November 26, 2020 13:07
Show Gist options
  • Save akio0911/f66f1de4653bd3b81419b12f2fb06a8e to your computer and use it in GitHub Desktop.
Save akio0911/f66f1de4653bd3b81419b12f2fb06a8e to your computer and use it in GitHub Desktop.
import UIKit
import MapKit
class ViewController: UIViewController {
@IBOutlet private weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func skytree(_ sender: Any) {
setRegion(latitude: 35.710063, longitude: 139.8107)
}
@IBAction func tokyoTower(_ sender: Any) {
setRegion(latitude: 35.658584, longitude: 139.7454316)
}
private func setRegion(latitude: CLLocationDegrees, longitude: CLLocationDegrees) {
let center = CLLocationCoordinate2D(
latitude: latitude,
longitude: longitude
)
let span = MKCoordinateSpan(
latitudeDelta: 0.01,
longitudeDelta: 0.01
)
let region = MKCoordinateRegion(center: center, span: span)
mapView.setRegion(region, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment