Created
December 6, 2017 18:00
-
-
Save manishkkatoch/8086d4385e382f6eaaa29961a5548f9a to your computer and use it in GitHub Desktop.
Usage of mocked CLLocationManager
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
// | |
// ViewController.swift | |
// mockLocation | |
// | |
// Created by Manich Katoch on 11/28/17. | |
// Copyright © 2017 mk. All rights reserved. | |
// | |
import UIKit | |
import MapKit | |
class ViewController: UIViewController, MKMapViewDelegate { | |
private let locationManager:CLLocationManager = CLLocationManager() | |
@IBOutlet weak var mapView: MKMapView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
mapView.delegate = self | |
MockLocationConfiguration.GpxFileName = "locationTrack" | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
locationManager.allowsBackgroundLocationUpdates = true | |
locationManager.requestAlwaysAuthorization() | |
mapView.showsUserLocation = true | |
} | |
} | |
extension ViewController : CLLocationManagerDelegate { | |
func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) { | |
let region = MKCoordinateRegion.init(center: userLocation.coordinate, span: MKCoordinateSpan.init(latitudeDelta: 0.15, longitudeDelta: 0.15)) | |
mapView.setRegion(region, animated: true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment