我整天都试过这个 - 看起来应该很简单 - 但我无法让MapView放大当前位置。
在模拟器中使用“Apple”作为测试位置 - 我没有得到任何错误并且它运行 - 但是视图只是保持美国的全景图蓝点 - 在加利福尼亚代表Apple地点。提前感谢任何帮助!
代码如下:
import MapKit
import UIKit
import CoreLocation
class MapViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
var locationManager: CLLocationManager!
func createLocationManager () {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = kCLDistanceFilterNone
}
func locationManager (manager:CLLocationManager!, didUpdateLocations locations:[AnyObject]!) {
if let firstlocation = locations.first as? CLLocation {
mapView.setCenterCoordinate(firstlocation.coordinate, animated: true)
let region = MKCoordinateSpanMake (1000,1000)
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
locationManager = CLLocationManager()
locationManager?.requestWhenInUseAuthorization()
self.mapView.showsUserLocation = true
}
答案 0 :(得分:0)
在模拟器中尝试Debug->Location->City Bicycle Ride
。这将为您提供持续更新。
还要确保设置locationManager的委托。