Skip to content

Instantly share code, notes, and snippets.

func setupLocationManager(){
// set delegate for location manager
if CLLocationManager.authorizationStatus() != CLAuthorizationStatus.authorizedAlways{
// Request to get alwayls location authorization
locationManager.requestAlwaysAuthorization()
}
locationManager.delegate = self
locationManager.distanceFilter = 1
func setupUserNotificationCenter(){
// request to receive notification
notificationCenter.requestAuthorization(options: [.alert, .sound, .badge, .carPlay], completionHandler: { (granted, error) in
if (error != nil) {
print("Notification Authorization Error: " + error!.localizedDescription)
}else{
print("Notification Authorization Granted: " + granted.description)
}
import UIKit
import CoreLocation
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate, UNUserNotificationCenterDelegate{
var window: UIWindow?
let locationManager = CLLocationManager()
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
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
func setupMapView(){
var annotationList = [MKPointAnnotation]()
var circleList = [MKCircle]()
let locationName = "Tokyo Tower"
let coordiate = CLLocationCoordinate2DMake(35.658626, 139.745471)
// setup annotation
let annotation = MKPointAnnotation()
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
}
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 setupLocationManager(){
if CLLocationManager.authorizationStatus() != CLAuthorizationStatus.authorizedAlways{
// Request to get alwayls location authorization
locationManager.requestAlwaysAuthorization()
}
// set delegate for location manager
locationManager.delegate = self
func setupUserNotificationCenter(){
notificationCenter.delegate = self
// request to receive notification
notificationCenter.requestAuthorization(options: [.alert, .sound, .badge, .carPlay], completionHandler: { (granted, error) in
if (error != nil) {
print("Notification Authorization Error: " + error!.localizedDescription)
}else{