我使用CLLoction管理器来获取location.but什么时候我开始我的位置然后它给我oldlocation先前存储在设备中.我想在首次启动应用程序时重置此i used flag的位置我使用newlocation并调用stopupdateinglocation和startupdatinglocation方法.但是oldlocation没有改变它显示旧位置.
我在用
startMonitoringSignificantLocationChanges
得到(lat,lon)值.我的问题是
- (void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation
[locationMangerObject startMonitoringSignificantLocationChanges];遇到后,方法不会被立即调用.内部didUpdateToLocation方法只保留两个全局双变量来保存纬度和经度,这些变量将根据从didUpdateToLocation方法获得的坐标设置.这些值被传递给web服务,因为didUpdateToLocation只被调用某些延迟,在这些延迟之间,(lat,lon)的参数将零作为其值并传递给服务,从而导致意外响应.
怎么做
- (void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation
在`[locationMangerObject startMonitoringSignificantLocationChanges]之后立即调用的方法; 遇到了.
请有人建议我解决这个问题的解决方案.
提前致谢.
我已经按如下方式配置了locationManager.
_locationManager = [[CLLocationManager alloc] init];
[_locationManager setDelegate:self];
[_locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[_locationManager setDistanceFilter:kCLDistanceFilterNone];
Run Code Online (Sandbox Code Playgroud)
当应用程序运行时,我从委托方法获得一些更新.当我不改变位置,并且移动设备静止约2小时后,我在前10分钟内收到大约10-12个更新,然后停止接收更新.
我所理解的是,理想的准确度是设备将继续尝试越来越精确的方法来获取当前位置的时间.所以在我的情况下,需要大约10分钟才能获得所需的精度.
我想确认这是否属实.还有一种方法可以让我获得定期的位置更新,即使设备没有移动?
我的appDelegate中有一个方法获取纬度和经度,并返回一个我可以在任何viewController中使用的字符串.
AppDelegate:
-(void)StartUpdating
{
locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
locManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locManager startUpdatingLocation];
}
#pragma mark
#pragma mark locationManager delegate methods
- (void)locationManager: (CLLocationManager *)manager
didUpdateToLocation: (CLLocation *)newLocation
fromLocation: (CLLocation *)oldLocation
{
float latitude = newLocation.coordinate.latitude;
strLatitude = [NSString stringWithFormat:@"%f",latitude];
float longitude = newLocation.coordinate.longitude;
strLongitude = [NSString stringWithFormat:@"%f", longitude];
//[self returnLatLongString:strLatitude:strLongitude];
}
-(NSString*)returnLatLongString
{
NSString *str = @"lat=";
str = [str stringByAppendingString:strLatitude];
str = [str …Run Code Online (Sandbox Code Playgroud) 这是一些简单的代码:
// ViewControllerA.m
-(void) viewDidLoad
{
[super viewDidLoad];
self.networkMonitor = [[NetworkMonitor alloc] init];
...
[self.networkMonitor.locationManager startUpdatingLocation];
...
}
Run Code Online (Sandbox Code Playgroud)
在网络监视器中:
// NetworkMonitor.m
-(id) init
{
self = [super init];
if (self != nil) {
self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager setDelegate:self];
}
return self;
}
...
// this is never called!
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"%s, location manager returned a new location.", __FUNCTION__);
...
}
// and neither is this
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"Error: %@", [error …Run Code Online (Sandbox Code Playgroud) 我正在检测用户是否已接受在我的应用程序中使用位置服务的请求,我在UI中有一个取决于此接受的切换开关.他们第一次切换开关(打开)时,触发了使用位置的请求.我想知道他们在那个警报中按哪个按钮.(接受或拒绝)现在我只是将其切换并让用户再次按下它(然后检测他们选择了哪个选项).
这有点草率,所以我想知道是否有办法检测这个特定的警报,或者由于它是由操作系统而不是应用程序触发而无法完成?我还没有尝试过,但是我认为我可以使用UIAlertView委托方法进行通用按钮按下,但希望能有更具体的内容.
UPDATE
我通过在触发位置请求时注册通知(并显示授权提示)来实现此功能.应用程序处于非活动状态(很像下拉通知栏).我只是在应用程序变为活动状态时触发通知,我只能在那里查询授权状态并更新我的UI.如果他们想要动态处理授权状态,我希望这有助于其他任何人.
我正在使用位置服务让我的应用程序保持更长时间,它在iOS6(设备和模拟器)中工作正常,但在iOS7中它没有调用此委托函数CLLocationManager,
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
Run Code Online (Sandbox Code Playgroud)
如何在iOS7中完成这项工作?
我有一个按钮,其中点击我授权我的应用程序启用位置服务.我想从警报中捕获允许按钮事件.当用户按下允许时,我的按钮颜色将变为其他颜色.我无法捕获允许按钮的回调.但是,我可以通过此链接捕获不允许按钮事件
请任何人都可以告诉我如何捕获允许按钮点击并成功我想要我的代码.
在Android中有一个方法叫做getLastLocation()允许你保存最后一个位置,如果GPS被禁用,例如,是否有任何功能在Swift中有效?
是否可以比较互联网GPS和真实GPS的结果之间的准确性?
我需要打开我的iOS应用程序特定位置设置.我知道我们可以通过以下方式打开常规位置设置:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root = LOCATION_SERVICES"]];*
我有两个问题:
以上是否有效且根据Apple指南(或)是否应该打开设置应用程序并允许用户更改设置?
我的要求是打开我的应用程序的特定位置设置 - 显示"始终","使用应用程序","从不",以便用户可以修改相同的位置设置.这可能吗
提前致谢.
iphone ×8
ios ×5
objective-c ×2
geolocation ×1
gps ×1
ios4 ×1
ios6 ×1
ios7 ×1
ios8 ×1
mapkit ×1
swift ×1
uialertview ×1