- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在播放一个 youtube 视频,该视频提供了一个基本示例,说明如何利用 Xcode 的定位服务为程序编写一种 map 用户界面。我按照设置程序的视频中的步骤进行操作,并在尝试编译应用程序时收到一个假设简单的“使用未声明的类型”错误。
https://www.youtube.com/watch?v=qrdIL44T6FQ - 链接到 youtube 视频。
问题出现在类创建行。
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate
{ // ^ Use of undeclared type
@IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreate-d.
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordingate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
self.location.stopUpdatingLocation()
}
func locationManager(manager: CLLocationManager, difFailWithError error: NSError)
{
print("Errors: " + error.localizedDescription)
}
}
我不确定为什么会出现错误。我在“Link Binary With Libraries”部分添加了 CoreLocation.framework。我确保将“NSLocationWhenInUseUsageDescription”添加到 Info.plist。我在视频中的 2:26 将 Map View Kit 连接到代码本身。
执行此操作的其他方法也很有趣。我只是想获得基本的位置服务许可,以便在程序中运行。
版本:Xcode 7.3.1 版
最佳答案
swift
我缺少导入 CoreLocation。我在我的文件顶部添加了以下行并且它起作用了。
import CoreLocation
关于ios - Swift:利用 CLLocationManagerDelegate 和 CoreLocation.framework 导致 "Use of undeclared type"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39026205/
#import #import @interface SomeClass : NSObject { CLLocation *location; //... } //... 代码似乎
我在我们的生产应用程序中遇到了 Apple 的 CoreLocation 线程崩溃。我无法在我的测试中重现它,也很难弄清楚它是在 CoreLocation 内部。目前它只发生在少数人口中,但我可以看到
当我尝试获取当前位置时,IOS 显示了警报 View ,例如““应用程序”想要使用您当前的位置”以及“不允许”和“确定”。我点击了“不允许”。然后,每当我打开应用程序并尝试获取当前位置时,它都不会再次
我试图实现一个单独的类来管理我的位置。每当我单击按钮时,我都想获得我的位置。 gpsFilter.h #import #import @interface gpsFilter : NSObject
如何使用 locationManager startMonitoringForRegion 方法开始监视多个区域 例如,我要监控三个区域 CLLocationCoordinate2D centreLo
出于某种原因,我似乎无法获取用户的位置。我买了 iOS 9 CookBook 并完全复制了他们的代码 这是 View Controller : import UIKit import CoreLoca
我试图让我的应用程序在用户加载应用程序后立即获取用户当前位置的经度和纬度。从这里我可以判断它们是否与某个点有一定距离,并据此调用不同的函数。 我可以通过 viewDidLoad 使其正常工作,但我不希
如果我正在编写的应用程序终止,我需要将当前位置存储到 iphone 的“磁盘”中。然后,当应用程序再次启动时,我想恢复这些信息。但是,CLLocation 坐标属性是只读的。 如何在程序调用之间保存此
我正在使用 CLLocationManager 捕获位置数据。我不太关心水平精度,但我希望速度尽可能准确。 有人知道 kCLLocationAccuracyThreeKilometers 是否足以满足
didUpdateLocations 没有触发- CLLocationManagerDelegate 已使用 View Controller 作为委托(delegate)正确实现 import Fou
设置kCLLocationAccuracy(locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation)时,哪种方法使
在我的应用程序中,我通过始终允许选项询问用户位置权限。从 iOS 13 开始,选项始终允许从弹出窗口中删除。所以我必须创建一个流程并检查是否已启用 always 选项。 我以为 CLLocationM
我正在尝试使用 CLLocationManager 获取用户位置。由于某种原因 locationManager:didUpdateLocations 从未被调用。下面是 View Controller
我已经将 CoreLocation 库和 NSLocationWhenInUseUsageDescription 添加到 info.plist,但是当我编译和运行时,它不显示当前位置或提示用户允许访问
我有一个仅使用 iPad 中的 GPS 芯片收集纬度/经度坐标的应用程序(IE 在 ios8 上没有 wifi 或蜂窝网络)。它似乎始终如一地工作,除非该应用程序闲置了大约一个小时(该应用程序仍处于打
我正在开发一个适用于健身(运行)的 iOS (7.0+) 应用程序,它使用用户的 GPS 位置、进行小型计算并将数据传输到低功耗蓝牙 (4.0) watch 。这个过程需要在后台进行,即使用户锁定了他
我一直在测试 CoreLocation 各个方面的准确性,并惊讶地发现传递给 CLLocationMangerDelegate 方法的新旧位置的准确性值:(void)locationManager:d
我正在尝试显示用户的平均速度,而且我还想显示数组的最大值。 我搜索了论坛并找到了很多方法来实现这一点,但没有任何效果。 我试过的是//最高速度和//平均速度 这是我的代码: // Location l
我目前正在尝试获取当前用户的设备移动速度。这是我的代码: import UIKit import Foundation import CoreLocation class ViewController
我正在使用 CoreLocation 框架获取我的速度和距离来计算平均速度。 在 CoreLocation 发出的第一个更新中,它显示了速度和行进距离的负值。我该如何解决这个问题? 速度是 locat
我是一名优秀的程序员,十分优秀!