我有一个应用程序,用于CLLocationManager跟踪用户的路线,沿着所采取的路径绘制点.该应用程序在后台使用必需的后台模式>应用程序寄存器进行位置更新.
据我所知,后台发生的任何事情都需要调用,locationManager:didUpdateToLocation:fromLocation因为这是每个位置更新调用的方法.
我遇到的问题是有时会停止调用.当用户的位置在大约15分钟左右的时间内没有太大变化时,似乎会发生这种情况.据我所知,调用locationManager:didUpdateToLocation:fromLocation只是停止,大概是为了节省电池.不幸的是,当你回到移动状态时,它不会再次恢复.
我认为无法覆盖此行为,因此我想使用通知中心通知用户应用程序不再记录路由.问题是,应用程序如何知道发生了这种情况?如果未调用locationManager:didUpdateToLocation:fromLocation,则无法触发我的通知.如果正在调用它,则不应触发通知.
是否有某种系统通知表明位置更新将停止?
我发现很难调试这个,因为当我出去测试设备上的位置时,我无法随身携带我的Mac(在模拟器中你只能做很多事情).任何调试技巧也将非常感谢!
我正在使用react-native-sensor从这些传感器中获取原始数据。
import {magnetometer, acclerometer} from 'react-native-sensors';
const subscription = accelerometer.subscribe(({ x, y, z, timestamp }) =>
console.log({ x, y, z, timestamp })
this.setState({ accelerometer: { x, y, z, timestamp } })
);
const subscription = magnetometer.subscribe(({ x, y, z, timestamp }) =>
console.log({ x, y, z })
this.setState({ magnetometer: { x, y, z, timestamp } })
);
Run Code Online (Sandbox Code Playgroud)
给定这6个数据点,我怎样才能得到程度和方向?什么是合适的算法?
我不明白这个答案中的算法。这个答案使用了 alpha、beta、gamma...与“x、y、z”相同吗?为什么只使用 3 个数据点而不是 6 个?为什么其他一些答案说需要加速度计数据(用于倾斜调整?)。为什么没有利用所有 6 个数据点的答案?
(注意:文档中有“磁力计”的拼写错误)
我想将数据库中的坐标列表拉入数组(在地图上显示之前).但是,在数据库中,它们的类型为Number,我无法弄清楚如何将它们转换为坐标.
这不起作用:我有一个ATM对象(坐标为atm机器),NSNumbers用于纬度和经度.这是一个索引为i的循环,以便逐个拉出它们.atmsArray已经加载了.
ATM *aATM = [self.atmsArray objectAtIndex:i];
CLLocationCoordinate2D coord=[[CLLocationCoordinate2D alloc] initWithLatitude:(CLLocationDegrees)aATM.Latitude longitude:(CLLocationDegrees)aATM.Longitude];
Run Code Online (Sandbox Code Playgroud)
显示错误:-CLLocationCoordinate2D不是ObjectiveC类名或别名 - 当预期浮点值时使用的-pointer值 - 当预期浮点值时使用的值
我尝试了一些不同的东西,但无法弄清楚.如果需要更多信息,请告诉我.
我试图用cllocation和mkreversegeocoder来修改城市名称.在我的viewdidload方法我istance cllocationmanager:
self.locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
locManager.desiredAccuracy = kCLLocationAccuracyBest;
[locManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)
之后:
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation
fromLocation:(CLLocation *)oldLocation {
//some code to retrieve my information
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc]
initWithCoordinate:newLocation.coordinate ];
geoCoder.delegate = self;
[geoCoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark
{
MKPlacemark *myPlacemark = placemark;
citta.text = [placemark locality];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
citta.text =@ "Unknow";
Run Code Online (Sandbox Code Playgroud)
应用程序仅在我第一次获得我的价值时起作用.在第二次应用程序崩溃.我认为是因为地理编码器已启动,我认为我必须只有一个运行.(但我真的不是这个......).在哪种方式我可以控制地理编码器正在运行?
我已经看到我可以使用cllocationcoordinate2d在我的viewdidload中使用mkreversegeocoder但是...以这种方式我可以检索newlocation.coordinate?
我已经部分解决了将地理编码器声明为类变量并进行检查的问题
if (self.geocoder != nil) {
[geocoder release];
}
Run Code Online (Sandbox Code Playgroud)
但是....如果在我的
- …Run Code Online (Sandbox Code Playgroud) 我正在开发我的第一个iPhone应用程序.我必须每隔x秒用设备速度更新一个标签.我创建了自己的CLController,我可以获得设备速度,但我不知道是否必须使用NSTimer更新我的标签.我该怎么做?
我希望能够通过允许用户在UIAlertView中键入地址或位置来更新MKMapView上显示的区域.我目前有:
if (geocoder.geocoding)
[geocoder cancelGeocode];
[geocoder geocodeAddressString:[[alertView textFieldAtIndex:0] text] completionHandler:^(NSArray *placemarks, NSError *error) {
if (!error) {
NSLog(@"Found a location");
} else {
NSLog(@"Error in geocoding");
}
NSLog(@"Num found: %d", [placemarks count]);
CLPlacemark *placemark = [placemarks objectAtIndex:0];
MKCoordinateRegion region;
region.center.latitude = placemark.region.center.latitude;
region.center.longitude = placemark.region.center.longitude;
MKCoordinateSpan span;
double radius = placemark.region.radius / 1000;
NSLog(@"Radius is %f", radius);
span.latitudeDelta = radius / 112.0;
//span.longitudeDelta = ???
region.span = span;
NSLog(@"Region is %f %f %f", region.center.latitude, region.center.longitude, span.latitudeDelta);
[mapView setRegion:region animated:YES];
}]; …Run Code Online (Sandbox Code Playgroud) 我希望您就哪种方法消耗更少的电池给我反馈.
我的应用程序将在后台运行并随着位置的变化而醒来,所以我想使用消耗更少电池的方法.
关于它是哪一个的任何想法?
谢谢
在我们的应用程序中,我使用CoreLocation来获取用户的位置.我认为对startUpdatingLocation的调用每次都会调用locationManager:didUpdateLocations.但是一旦它第一次被召唤,他们就再也不会被召唤了.
在我的AppDelegate.m中:
- (void) startStandardUpdates {
if (_locationManager == nil) {
_locationManager = [[CLLocationManager alloc] init];
[_locationManager setDelegate:self];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.distanceFilter = 10;
[_locationManager startUpdatingLocation];
} else {
NSLog(@"[LOCATION]: Location Manager already exists.");
[_locationManager startUpdatingLocation];
}
}
Run Code Online (Sandbox Code Playgroud)
然后由NSTimer调用它:
- (void) startTask {
NSLog(@"Start task called.");
[NSTimer scheduledTimerWithTimeInterval:15
target:self
selector:@selector(actualTask)
userInfo:nil
repeats:YES];
}
- (void) actualTask {
NSLog(@"[TASK]: Starting location service...");
[self startStandardUpdates];
}
Run Code Online (Sandbox Code Playgroud)
上面的代码应该每15秒调用一次startUpdatingLocation,但是第二次没有调用didUpdateToLocation方法(第一次成功调用了...).
有没有办法以编程方式调用(或强制)didUpdateToLocation?或者我们必须等到didUpdateToLocation获取位置?我已经搜索了每隔x分钟/秒获取用户位置的方法,但似乎没有人成功实现这一点.我想做的只是Android与Service类的相关(iOS没有这个).
任何帮助,将不胜感激.
谢谢.
我目前正在开发一个使用CLLocationManager且精度最低的应用程序(kCLLocationAccuracyThreeKilometers).但是,每隔几分钟我需要获得一个准确的用户位置,因此我在计时器到期时将精度设置为kCLLocationAccuracyBest.
显然,CLLocationManager开始更新位置,从不准确的位置到更准确的位置.但问题是,我不知道如何检测何时达到最佳位置精度,所以我永远不知道何时有最佳位置可供使用.
有人知道这个问题的解决方案吗?非常感谢.
我在我的iPad App中使用CLLocationManager类来获取当前位置.
我使用下面的代码来获取地址详细信息,
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSUserDefaults *oIsLocation = [NSUserDefaults standardUserDefaults];
if([oIsLocation boolForKey:@"IsLocation"])
{
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
if (newLocation.horizontalAccuracy < 0) return;
if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy)
{
if(bestEffortAtLocation.coordinate.latitude != newLocation.coordinate.latitude && bestEffortAtLocation.coordinate.longitude != newLocation.coordinate.longitude)
{
[self saveLocation:newLocation];
self.bestEffortAtLocation = newLocation;
[self saveUserLocation];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在进行反向地理编码以获取详细信息如下:
NSLog(@"placemark.ISOcountryCode %@",placemark.ISOcountryCode);
NSLog(@"placemark.country %@",placemark.country);
NSLog(@"placemark.postalCode %@",placemark.postalCode);
NSLog(@"placemark.administrativeArea %@",placemark.administrativeArea);
NSLog(@"placemark.locality %@",placemark.locality);
NSLog(@"placemark.subLocality %@",placemark.subLocality);
NSLog(@"placemark.subThoroughfare %@",placemark.subThoroughfare);
Run Code Online (Sandbox Code Playgroud)
placemark.locality给出了城市名称,但没有全名,如北卡罗来纳州只有NC.
当我的客户在美国使用应用程序时,而不是像"北卡罗莱纳州"这样的全名,他们获得NC,圣查尔斯获得圣查尔斯等.
有没有办法获得全名?
cllocation ×10
ios ×6
iphone ×3
objective-c ×2
clgeocoder ×1
cocoa-touch ×1
coordinates ×1
geolocation ×1
ipad ×1
javascript ×1
mkmapview ×1
nstimer ×1
sensors ×1