Created
August 23, 2019 00:52
-
-
Save susanna2222/f7f02f979b77c93f8db06511378d3c09 to your computer and use it in GitHub Desktop.
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
import UIKit | |
import MapKit | |
import CoreLocation | |
class ViewController: UIViewController, MKMapViewDelegate { | |
@IBOutlet weak var mapView: MKMapView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// setup Map View on User Location | |
let noLocation = CLLocationCoordinate2D() | |
let span = MKCoordinateSpan(latitudeDelta: 0.001, longitudeDelta: 0.001) | |
let viewRegion = MKCoordinateRegion(center: noLocation, span: span) | |
mapView.delegate = self | |
mapView.region = viewRegion | |
mapView.showsUserLocation = true | |
mapView.userTrackingMode = .follow | |
setupMapView() | |
} | |
func setupMapView(){ | |
var annotationList = [MKPointAnnotation]() | |
var circleList = [MKCircle]() | |
let locationName = "Tokyo Tower" | |
let coordiate = CLLocationCoordinate2DMake(35.658626, 139.745471) | |
// setup annotation | |
let annotation = MKPointAnnotation() | |
annotation.coordinate = coordiate | |
annotation.title = locationName | |
annotationList.append(annotation) | |
// setup circle | |
let circle = MKCircle(center: coordiate, radius: 50) | |
circleList.append(circle) | |
// add to map view | |
mapView.addAnnotations([annotation]) | |
mapView.addOverlays([circle]) | |
} | |
func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) { | |
let span = MKCoordinateSpan(latitudeDelta: 0.001, longitudeDelta: 0.001) | |
let region = MKCoordinateRegion(center: userLocation.coordinate, span: span) | |
mapView.region = region | |
} | |
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { | |
let circleRenderer = MKCircleRenderer(overlay: overlay) | |
circleRenderer.strokeColor = UIColor(red: 66/255, green: 133/255, blue: 244/255, alpha: 0.80) | |
circleRenderer.lineWidth = 1.0 | |
circleRenderer.fillColor = UIColor(red: 66/255, green: 133/255, blue: 244/255, alpha: 0.20) | |
return circleRenderer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment