- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我的 View Controller 上有这段代码,但这不起作用:
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
var location: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
location=CLLocationManager()
location.delegate = self
location.desiredAccuracy=kCLLocationAccuracyBest
location.startUpdatingLocation()
}
func locationManager(location:CLLocationManager, didUpdateLocations locations:AnyObject[]) {
println("locations = \(locations)")
label1.text = "success"
}
我拥有在其他帖子中阅读的权限。但我从来没有,没有 println..
谢谢!!
最佳答案
先在plist文件中加入这两行
1) NSLocationWhenInUseUsageDescription
2) NSLocationAlwaysUsageDescription
然后这是类工作完成实现这个
import UIKit
import CoreLocation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var window: UIWindow?
var locationManager: CLLocationManager!
var seenError : Bool = false
var locationFixAchieved : Bool = false
var locationStatus : NSString = "Not Started"
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
initLocationManager();
return true
}
// Location Manager helper stuff
func initLocationManager() {
seenError = false
locationFixAchieved = false
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.locationServicesEnabled
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
}
// Location Manager Delegate stuff
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
locationManager.stopUpdatingLocation()
if (error) {
if (seenError == false) {
seenError = true
print(error)
}
}
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: AnyObject[]!) {
if (locationFixAchieved == false) {
locationFixAchieved = true
var locationArray = locations as NSArray
var locationObj = locationArray.lastObject as CLLocation
var coord = locationObj.coordinate
println(coord.latitude)
println(coord.longitude)
}
}
func locationManager(manager: CLLocationManager!,
didChangeAuthorizationStatus status: CLAuthorizationStatus) {
var shouldIAllow = false
switch status {
case CLAuthorizationStatus.Restricted:
locationStatus = "Restricted Access to location"
case CLAuthorizationStatus.Denied:
locationStatus = "User denied access to location"
case CLAuthorizationStatus.NotDetermined:
locationStatus = "Status not determined"
default:
locationStatus = "Allowed to location Access"
shouldIAllow = true
}
NSNotificationCenter.defaultCenter().postNotificationName("LabelHasbeenUpdated", object: nil)
if (shouldIAllow == true) {
NSLog("Location to Allowed")
// Start location services
locationManager.startUpdatingLocation()
} else {
NSLog("Denied access: \(locationStatus)")
}
}
}
关于ios - 如何快速使用 CLLocationManager 获取位置用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24252645/
我在主线程上调用 -[CLLocationManager requestWhenInUseAuthorization]。我已经设置了我的委托(delegate),并在 info.plist 中为 NS
这是我的代码,显示 map 上当前位置的警报和蓝点: MapName.h #import #import #import @interface MapName : UIViewControlle
我怎样才能不出错地执行以下操作? locationManager.delegate = self 行表示它不能 Cannot assign value of type '(APPLocationMan
我需要一直跟踪用户位置(但不要耗尽电池电量)。 我了解在应用程序终止后获取更新的唯一方法是使用 startMonitoringSignificantLocationChanges。 来自苹果关于 st
在我的标题中放置 CLLocationManager *locationManager; @property (nonatomic, retain) CLLocationManager *locati
我正在按照几个教程中的描述实现 CLLocationManager。 一切工作正常,直到 LocationManager 收到第二次更新。然后就会发生内存泄漏。 Instruments 告诉我,泄漏的
我正在尝试获取 iOS 设备(特别是我的 iPhone)上的当前位置。 我正在使用this苹果的例子。 调用 stopUpdatingLocations 之前的超时时间是 60 秒。 当我将desir
是否可以在后台“挂起” cllocationmanager? 我试图停止管理器,然后在特定时间在后台重新启动它。这可能吗?我尝试停止管理器并启动 nstimer,但它不起作用,因为 nstimer 不
如果我有一个选项卡栏应用程序,并计划在不同的选项卡中使用核心位置,是否有一个好的通用位置来放置用于分配/初始化 CLLocationManager 的代码,并在调用 startUpdatingLoca
我有一个 Mac 应用程序,想要使用核心位置,但是,当我没有使用 wifi 但使用以太网电缆连接时,核心位置 (CLLocationManager) 报告操作无法完成。 确切的错误消息是 The op
我正在开发一个跟踪应用程序,它需要在 map 上显示跟踪路径。当我开始更新位置并且安装后没有移动设备时,locationManagar报告错误的位置更新, 我正在根据报告的位置点绘制路线, 另外当用户
从iOS9开始,我们在CCLocationManager中遇到了一些奇怪的问题。 iOS 7-8没有问题。怪异的位置会导致应用程序出错。该应用程序在开车时使用,我们有大约50位TestFlight测试
我正在使用 CLLocationManager要访问用户位置,以下委托(delegate)方法返回不准确的坐标 -(void)locationManager:(CLLocationManager *)
我的应用程序中有一个映射功能。它属于选项卡栏 Controller 选项卡之一。 我遇到的问题是该应用程序在启动后立即要求位置权限。 在用户真正进入应用程序的 map 部分之前,我不想用与位置相关的问
我有一个 iOS 应用程序,它是一个选项卡式应用程序,带有 3 个 View Controller ,所有这些都需要知道手机何时进入特定地理区域。 我们监控的区域是在运行时通过 Web 界面提供的,因
当我尝试尝试 LBS 应用程序时,我遇到了问题。在模拟器中测试时,它似乎工作。然后,我在 iPhone 上试了一下。它没有按预期工作。 当我启动应用程序时,它显示了我的位置纬度、经度、距离等所有信息。
我有两个不同的类,其中之一是 LocationService,仅用于确定位置。问题是我不知道为什么它不更新坐标变量。 View Controller : import UIKit class View
我是 swift 新手 - 目前,当我第一次通过 override func awakeFromNib() 在 init 上调用 setupLocationManager() 时,我的当前位置仅在控制
我正在阅读 application:didFinishLaunchingWithOptions:方法并从 NSHipster 中发现以下代码: @import CoreLocation; @inter
位置管理器使用辅助 GPS 来确定用户的位置,使用来自 wifi 和蜂窝适配器的信息来提高返回位置的准确性和电池效率。但是,该文档没有明确说明为此使用 wifi/手机信号信息是否涉及任何可能消耗用户手
我是一名优秀的程序员,十分优秀!