【发布时间】:2018-03-05 10:03:04
【问题描述】:
我有一个使用 mapkit 和 corelocation 构建的 ios 应用程序。该应用程序可以正常工作,但地图没有在 xcode 模拟器中确定我当前的位置,并且当在实际设备上运行时,它不会显示景观和其他内容。只是一张只有一条道路的空白地图,不能放大或缩小。 下面是我的代码
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//IF we have coordinate from manager
//let location = locations.last as CLLocation
if let location = locationManager.location?.coordinate{
userLocation = CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
let region = MKCoordinateRegion(center: userLocation!, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
mapView.setRegion(region, animated: true)
mapView.removeAnnotations(mapView.annotations)
let annotation = MKPointAnnotation()
annotation.coordinate = userLocation!
annotation.title = "Me!"
mapView.addAnnotation(annotation)
}
}
可根据要求提供其他代码
【问题讨论】:
-
每次 CCLocationManager 获得有效位置时都会执行该代码,因此该代码每秒执行很多次,请尝试仅使用标志执行此代码一次,必须解决您的问题
-
它永远不会得到我的位置,但如果我在 Xcode 模拟器中运行它,它会显示 Infinite Loop Apple inc
-
你打电话给
self.locationManager.startUpdatingLocation()了吗??并将您的 viewController 添加为委托 -
我确实做到了
-
它很奇怪吗?那么你的委托方法被调用了吗?