我有一个 Mac 应用程序,想要使用核心位置,但是,当我没有使用 wifi 但使用以太网电缆连接时,核心位置 (CLLocationManager) 报告操作无法完成。
确切的错误消息是
The operation couldn't be completed. (kCLErrorDomain error 0.)
Run Code Online (Sandbox Code Playgroud)
如果我总是连接到同一个路由器(即 wifi 或以太网电缆),为什么 CLLocationManager 仅适用于 wifi 而不适用于以太网连接?
任何建议将不胜感激。
谢谢。
编辑:
这是一些代码。
我将位置管理器定义为实例变量,如下所示
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:ICMinimumUpdateDistance];
Run Code Online (Sandbox Code Playgroud)
然后我像这样监视位置管理器的委托方法,
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// Filter out points before the last update
NSTimeInterval timeSinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:dateOfLastUpdate];
if (timeSinceLastUpdate > 0)
{
//Do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
我还使用委托方法检查错误
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"Location Error:%@", [error localizedDescription]);
} …Run Code Online (Sandbox Code Playgroud) 首先,免责声明是我的目标是iOS 5,所以很可能是我的问题的根源,但如果不是......
我正在尝试编写一个通过CoreLocation管理位置更新的简单类.但是,我看到一些非常奇怪的行为.我有一个自定义类,基本上包装CLLocationManager和委托方法.这是界面:
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@protocol CLZipCodeFetcherDelegate
@optional - (void)didReceiveZipCode:(NSString *)zipCode;
@end
@interface CLZipCodeFetcher : NSObject <CLLocationManagerDelegate> {
id <CLZipCodeFetcherDelegate> delegate;
CLLocationManager *locationManager;
}
@property (strong, readwrite) id <CLZipCodeFetcherDelegate> delegate;
@property (strong, read write) CLLocationManager *locationManager;
- (void)getZipCode;
@end
Run Code Online (Sandbox Code Playgroud)
和实现(忽略与邮政编码相关的东西 - 这是该类最终要做的事情,但是现在我只是想从CoreLocation获取一些坐标):
#import "CLZipCodeFetcher.h"
@implementation CLZipCodeFetcher
@synthesize delegate, locationManager;
- (id) init {
self = [super init];
if (self != nil) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 10.0f; // we don't need to …Run Code Online (Sandbox Code Playgroud) 我想要实现地理定位通知,如应用提醒.这就是我已经做过的事情:
在App代表中:
self.locationManager = [[[CLLocationManager alloc] init] autorelease]; /* don't leak memeory! */
[self.locationManager setDelegate:self];
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
}
Run Code Online (Sandbox Code Playgroud)
并且视图控制器中的这一个开始监视:
CLLocationCoordinate2D location2D = mapView.region.center;
CLRegion *regionForMonitoring = [[CLRegion alloc] initCircularRegionWithCenter:location2D radius:1 identifier:@"RegionIdentifier"];
[[Utils getLocationManager] startMonitoringForRegion:regionForMonitoring];
Run Code Online (Sandbox Code Playgroud)
现在我不知道我需要做些什么才能使用这些信息来发送本地通知.
reminders mkmapview cllocationmanager ios uilocalnotification
我正在使用 CLLocation 机制来获取 iPhone 中的坐标。我从“定位我”的例子中获取了一个例子,并对其进行了一些扩展。但是我提出了准确性问题。
那么问题来了,有没有办法让iPhone使用GPS而不是三角天线来获取位置呢?
很高兴知道是否有办法提高使用天线时的精度,但到目前为止我得到的最好结果是 65 米。
我正在开发一个iPhone应用程序,我正在使用GPRS不时更新用户的当前位置.
我发现电池正在耗尽.
任何人都可以帮我解决这个问题吗?
如何找到距离用户最近的位置?基本上,我有一堆CLLocation,我想找到最接近用户的那个.我已检索到用户当前位置但我想找到最近的位置CLLocation.我该怎么做呢?你可以NSLog就近.
我可以使用CLLocationManagerDelegate获取纬度、经度、城市和地址。但我无法获得某些位置的邮政编码。有没有办法使用经纬度接近邮政编码?
提前致谢。
我正在呼叫startUpdatingLocation()一个CLLocationManager,并且在didUpdateLocations我正在调用的方法中,stopUpdatingLocation()当精度小于100米时,就像这样:
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
var lastLocation: CLLocation = locations.last! as! CLLocation
var accuracy = lastLocation.horizontalAccuracy
if (accuracy < 100) {
locationCoordinate = lastLocation.coordinate
locationManager.stopUpdatingLocation()
getData()
}
}
Run Code Online (Sandbox Code Playgroud)
但是,除非我设置为to ,否则didUpdateLocations调用后仍然会调用该方法一两次.显然,这也多次调用我的方法,这是我不想要的.如何在不设置等于的情况下停止?stopUpdatingLocations()locationManagernilgetData()locationManagernil
我正在尝试将 cllocationcoordinate2d 转换为 cllocation。我在下面代码的第 12 行收到错误“容器文字中的预期表达式”。我还在第 13 行收到错误“无法将 cllocationcoordinate2d 类型的值转换为期望值 cllocation”,但这是因为第 12 行工作不正常。
@IBAction func makeEvent(sender: UIButton)
{
let center = CLLocationCoordinate2D(latitude: loc1.coordinate.latitude, longitude: loc1.coordinate.longitude)
let lat: CLLocationDegrees = center.latitude
let long: CLLocationDegrees = center.longitude
self.pointAnnotation1 = MKPointAnnotation()
self.pointAnnotation1.title = "Event"
self.pointAnnotation1.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: long)
self.pinAnnotationView = MKPinAnnotationView(annotation: self.pointAnnotation1, reuseIdentifier: nil)
self.mapView?.centerCoordinate = self.pointAnnotation1.coordinate
self.mapView.addAnnotation(self.pinAnnotationView.annotation!)
CLLocation *center = [[CLLocation alloc] initWithLatitude:latt longitude:longg]
eventRecord.setObject(center, forKey: "event")
let publicData = CKContainer.defaultContainer().publicCloudDatabase
publicData.saveRecord(eventRecord) { record, error in
}
if error == …Run Code Online (Sandbox Code Playgroud) 我创建了一个位置跟踪 ios 应用程序(使用 CocoaLumberjack 库写入日志文件)。因此启用了后台位置更新并用于我的测试(我几乎在后台运行了 8 小时)。当应用程序进入实时商店时。我们的应用程序中发生了很多问题。当应用程序转到后台位置跟踪无法正常工作时。它不会在一段时间内将用户位置发送到服务器。所以我从客户端获取日志文件并查看日志文件中是否存在时间间隔。我经常获取用户位置(每隔一秒)。所以我认为应用程序在日志文件中出现间隙时进入暂停状态?为什么即使我经常在后台获取位置,应用程序也会进入暂停状态?应用程序是否有理由进入暂停状态?搜索了很多找不到任何有效的详细信息?
func startTimer()
{
if bgTimer == nil
{
bgTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.startLocationChanges), userInfo: nil, repeats: true)
}
}
func stopTimer()
{
if bgTimer != nil
{
bgTimer?.invalidate()
bgTimer = nil
}
}
@objc func startLocationChanges() {
locationManager.delegate = self
locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = false
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//let lastLocation = locations.last!
// Do something with the location. …Run Code Online (Sandbox Code Playgroud) ios ×7
iphone ×4
objective-c ×3
swift ×3
background ×1
batterylevel ×1
cllocation ×1
cloudkit ×1
cocoa ×1
gps ×1
macos ×1
mkmapview ×1
reminders ×1
xcode ×1