我的应用程序跟踪位置在后台...位置背景模式已启用,我使用
[self.locationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)
这很好用,iOS7-8但它停止了工作iOS9
在模拟器中它可以工作,但在真实设备上我在后台没有回调...当在iOS8设备上运行相同的代码时,我得到正常的回调
这记录了吗?为什么它在模拟器中工作而不在设备中?这是一个错误吗?
当使用startSignificantChangeUpdates它在iOS9上工作时,我想知道这是否是某种节电功能,他们可能禁止startUpdatingLocation
我只能让我的CLLocationManager进行授权.(在ios8下迅速)我甚至添加了一个显式的requestAlwaysAuthorization调用(在ios7下我不需要使用objC)
func finishLaunch() {
//ask for authorization
let status = CLLocationManager.authorizationStatus()
if(status == CLAuthorizationStatus.NotDetermined) {
self.locationManager.requestAlwaysAuthorization();
}
else {
self.startMonitoring()
}
...
}
Run Code Online (Sandbox Code Playgroud)
回调永远不会得到任何东西,但NotDermined并没有向用户显示UIAlertView.
func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if(status == CLAuthorizationStatus.NotDetermined) {
println("Auth status unkown still!");
}
self.startMonitoring()
}
Run Code Online (Sandbox Code Playgroud)
我做错了吗? - 对我来说感觉像个臭虫,但我想要一些反馈
我没有在sim或设备上获得任何位置回调.我已经调用了这个代码:
- (void)startLocationCallbacks: (NSObject*) ignore
{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = MINIMUM_METERS;
[locationManager startUpdatingLocation];
NSLog(@"[DEBUG] [locationManager startUpdatingLocation] (%@, %@)", locationManager, locationManager.delegate);
}
Run Code Online (Sandbox Code Playgroud)
并在两者的顶部记录日志
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
Run Code Online (Sandbox Code Playgroud)
和
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
Run Code Online (Sandbox Code Playgroud)
但是这两个日志语句都没有被调用.为我的应用启用了位置通知(如设置中所示,加上我说"允许".)
我没有获得位置更新的可能原因是什么?
配置/其他信息:
谢谢!
我有一个带有地图和按钮的视图(比如地图应用程序一次),允许用户在地图上居中和缩放他当前的位置.如果我不能使用locationServicesEnabled方法(总是返回YES),我应该创建一个BOOL属性来检查是否调用了didFailWithError方法并知道我是否可以调用button方法?
谢谢阅读.
编辑:
此代码对我不起作用.我正在使用模拟器.在询问locationServicesEnabled时,我总是得到YES.
// Gets the user present location.
- (IBAction)locateUser:(id)sender {
if([CLLocationManager locationServicesEnabled]) {
CLLocationCoordinate2D coordinate;
coordinate.latitude = self.mapView.userLocation.location.coordinate.latitude;
coordinate.longitude = self.mapView.userLocation.location.coordinate.longitude;
[self zoomCoordinate:coordinate];
} else {
[[[[UIAlertView alloc] initWithTitle:@"Warning." message:@"Location services are disabled."
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease] show];
}
}
Run Code Online (Sandbox Code Playgroud) 我用Swift 2将Xcode 6更新为Xcode 7 beta.我收到此错误,我无法找到解决方法,请帮助我.谢谢.这是我的代码:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
let location = locations.last as! CLLocation
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.map.setRegion(region, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Objective-C method 'locationManager:didUpdateLocations:' provided by method 'locationManager(_:didUpdateLocations:)' conflicts with optional requirement method 'locationManager(_:didUpdateLocations:)' in protocol 'CLLocationManagerDelegate'
从iOS9开始,我们在CCLocationManager上遇到一些奇怪的问题.iOS 7-8没有问题.奇怪的位置会导致应用程序出错.该应用程序在驾驶汽车时使用,我们在TestFlight中有大约50名测试用户,其中一些正在报告这些问题.
应用程序对位置更新做出反应,每个位置更新,每个25米,每个50米都有事可做.为了测试,我将所有这些位置存储在一个数组中.我们的测试用户有一个按钮,可以通过邮件将GPX格式的历史记录发送给我.
例如,发送给我的以下12个地点:
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="flitsmeister-ios-app-test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<wpt lat="51.28165091" lon="5.77329012">
<datetimegps>2015-09-29T04:36:55.371</datetimegps>
<datetimeprocessed>2015-09-29T04:36:55.460</datetimeprocessed>
<course>61.5</course>
<speed>13.3</speed>
<accuracyhorizontal>5.0</accuracyhorizontal>
<accuracyvertical>3.0</accuracyvertical>
<altitude>33.1</altitude>
<sequencenr>0</sequencenr>
</wpt>
<wpt lat="51.28138654" lon="5.77244497">
<datetimegps>2015-09-29T04:36:55.506</datetimegps>
<datetimeprocessed>2015-09-29T04:36:55.523</datetimeprocessed>
<course>69.3</course>
<speed>13.5</speed>
<accuracyhorizontal>5.0</accuracyhorizontal>
<accuracyvertical>3.0</accuracyvertical>
<altitude>33.7</altitude>
<sequencenr>1</sequencenr>
</wpt>
<wpt lat="51.28171319" lon="5.77345935">
<datetimegps>2015-09-29T04:36:56.371</datetimegps>
<datetimeprocessed>2015-09-29T04:36:56.441</datetimeprocessed>
<course>61.2</course>
<speed>13.2</speed>
<accuracyhorizontal>5.0</accuracyhorizontal>
<accuracyvertical>3.0</accuracyvertical>
<altitude>33.0</altitude>
<sequencenr>2</sequencenr>
</wpt>
<wpt lat="51.28138654" lon="5.77244497">
<datetimegps>2015-09-29T04:36:56.562</datetimegps>
<datetimeprocessed>2015-09-29T04:36:56.571</datetimeprocessed>
<course>69.3</course>
<speed>13.5</speed>
<accuracyhorizontal>5.0</accuracyhorizontal>
<accuracyvertical>3.0</accuracyvertical>
<altitude>33.7</altitude>
<sequencenr>3</sequencenr>
</wpt>
<wpt lat="51.28177064" lon="5.77362548">
<datetimegps>2015-09-29T04:36:57.371</datetimegps>
<datetimeprocessed>2015-09-29T04:36:57.440</datetimeprocessed>
<course>60.1</course>
<speed>13.4</speed>
<accuracyhorizontal>5.0</accuracyhorizontal>
<accuracyvertical>3.0</accuracyvertical>
<altitude>32.9</altitude>
<sequencenr>4</sequencenr>
</wpt>
<wpt lat="51.28138654" lon="5.77244497">
<datetimegps>2015-09-29T04:36:57.541</datetimegps>
<datetimeprocessed>2015-09-29T04:36:57.558</datetimeprocessed>
<course>69.3</course> …Run Code Online (Sandbox Code Playgroud) 我需要检查用户位置是否属于MKCoordinateRegion.我很惊讶没有为此找到简单的功能,例如:CGRectContainsCGPoint(rect,point).
我找到了以下代码:
CLLocationCoordinate2D topLeftCoordinate =
CLLocationCoordinate2DMake(region.center.latitude
+ (region.span.latitudeDelta/2.0),
region.center.longitude
- (region.span.longitudeDelta/2.0));
CLLocationCoordinate2D bottomRightCoordinate =
CLLocationCoordinate2DMake(region.center.latitude
- (region.span.latitudeDelta/2.0),
region.center.longitude
+ (region.span.longitudeDelta/2.0));
if (location.latitude < topLeftCoordinate.latitude || location.latitude > bottomRightCoordinate.latitude || location.longitude < bottomRightCoordinate.longitude || location.longitude > bottomRightCoordinate.longitude) {
// Coordinate fits into the region
}
Run Code Online (Sandbox Code Playgroud)
但是,我不确定它是否准确,因为文档没有准确指定区域矩形的计算方式.
必须有更简单的方法来做到这一点.我是否忽略了MapKit框架文档中的某些功能?
我使用具有数字值的方法相机,如下所示:
camera = [GMSCameraPosition cameraWithLatitude:37.35 longitude:-122.0 zoom:6];
Run Code Online (Sandbox Code Playgroud)
我需要通过计时器自动重绘当前位置的地图:
-(void)gmapRedraw{
NSLog(@"gmapRedraw");
// self.MapView.camera
[locationManager startUpdatingLocation];
NSLog(@"lat %f, lon %f", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude);
camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude//37.36//-37.81319//-33.86
longitude:locationManager.location.coordinate.longitude//-122.0//144.96298//151.20
zoom:6];
self.MapView.camera = camera;
}
-(void)timer{
[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(gmapRedraw)
userInfo:nil
repeats:YES];
}
Run Code Online (Sandbox Code Playgroud)
但如果我通过触摸改变它,我怎么能得到当前的变焦?
自折旧以来initCircularRegionWithCenter:radius:identifier:,您将如何定义要监控的区域CLLocationManager?
我想使用MKMapView使用默认的呼吸蓝色针来显示用户当前位置,我想同时记录用户移动.有没有什么方法可以使用GPS管理器(不确定这是否是一个CLLocationManager)MKMapView在我们启用它时显示用户位置?
我知道我可以创建自己的CLLocationManager.但这感觉就像为我的应用程序增加了开销,我希望地图和我的跟踪保持同步.
我已经探索了以下想法但没有成功:
[MKMapView showUserLocation:YES]和在userLocation字段上添加KVO .这不起作用,我想知道这是否是由于该userLocation字段是只读的事实.[MKMapView showUserLocation:YES],使用,创建MKMapViewDelegate并添加跟踪.这不起作用,因为注释视图显然只被请求一次???CLLocationManager并尝试手动添加蓝色图钉.不幸的是,我没有在可用的引脚类型中找到蓝色引脚,所以我尝试手动创建用户注释而没有成功.有没有人知道如何实现这一点,仍然可以从蓝色引脚中受益,或者是我唯一的解决方案,使用a CLLocationManager并创建我自己的引脚?
ios ×4
iphone ×3
objective-c ×2
cllocation ×1
clregion ×1
cocoa-touch ×1
google-maps ×1
gps ×1
ios7 ×1
ios8 ×1
ios9 ×1
mkmapview ×1
swift ×1
swift2 ×1
xcode7 ×1
xcode7-beta2 ×1
zoom ×1