Skip to content

Instantly share code, notes, and snippets.

@manishkkatoch
Created December 6, 2017 18:00
Show Gist options
  • Save manishkkatoch/8086d4385e382f6eaaa29961a5548f9a to your computer and use it in GitHub Desktop.
Save manishkkatoch/8086d4385e382f6eaaa29961a5548f9a to your computer and use it in GitHub Desktop.
Usage of mocked CLLocationManager
//
// 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