The below code worked just one time and now all of the sudden it is not showing a point of interest (POI). I tried it on two different machines and am getting the same behavior. This is what has me puzzled, is it the code or my simulator settings.
I cleaned the project, made sure I had the simulator on custom. I did have the longitude and latitude printing now all of a sudden it is not printing in the console either.
import UIKit import MapKit import CoreLocation
class MapViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet var map: MKMapView!
var manager:CLLocationManager!
var latitude:Double = 0.0
var longitude:Double = 0.0
var location:Double = 0.0
override func viewDidLoad() {
super.viewDidLoad()
print("init")
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy - kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("test test test")
let userLocation:CLLocation = locations[0]
self.latitude = userLocation.coordinate.latitude
self.longitude = userLocation.coordinate.longitude
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = "Army Recruiting"
request.region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 1600, 1600)
MKLocalSearch(request: request).startWithCompletionHandler { (response, error) in
guard error == nil else { return }
guard let response = response else { return }
guard response.mapItems.count > 0 else { return }
let randomIndex = Int(arc4random_uniform(UInt32(response.mapItems.count)))
let mapItem = response.mapItems[randomIndex]
mapItem.openInMapsWithLaunchOptions(nil)
}
print("\(self.longitude) \(self.latitude)")
}
----------------------UPDATE 1--------------------
Updating location via simulator
I have noticed the below function is not running:
func locationManager(manager: CLLocationManager, didUpdateLocations
locations: [CLLocation])
---------------------Update 2--------------------
The app worked once then stopped. Not sure what is going on. Yes I added NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription


