我的应用程序使用CLLocationManager从设备获取位置更新。
我以为,当设备处于飞行模式时,我不会获得位置更新。但是我愿意。
我之所以认为这是因为Apple表示“飞行模式”会关闭Wifi,蜂窝,蓝牙和GPS。请参阅:http: //support.apple.com/kb/ht1355
那么,如何以似乎合理的坐标获取位置更新?
如何将CLLocation转换为CLLocationDegrees,以便我可以创建CLLocationCoordinate2D结构?
基本上,当我的应用程序第一次启动时,会出现"启用位置服务"提示.当用户点击"允许"时,我想开始更新用户位置并放大该区域.
在我的viewDidLoad中,我启动了位置管理器,但不幸的是,在用户有机会点击"允许"之前加载了视图.在第二次启动应用程序时一切正常,因为用户已经允许定位服务
我的问题是如何捕获点击允许的事件,以便我可以运行代码来放大一个区域?
我尝试过使用-(void)locationManager:didChangeAuthorizationStatus:但是当用户点击允许时它似乎没有调用此委托方法.
希望这是有道理的我对此非常新.
可能重复:
iOS 6和位置服务无法正常工作
我们的应用程序的位置服务已在iOS 6中停止运行.它们在iOS 5中运行良好.当我调用CLLocationManager的startUpdatingLocation方法时,它从不提示用户访问,我们的应用程序不会显示在"设置位置服务"页面中.
有人见过这个吗?我真的不知道在哪里看.我已经尝试将我们的应用程序剥离到一个视图控制器,它仍然无法正常工作.也许在构建设置中的东西?
编辑:我创建了一个新目标,它在那里工作.
我有两组地理坐标,我正在尝试计算它们之间的距离.我已经做了一些挖掘,但无法弄清楚如何做到这一点.我试图获得用户(userLatitude/userLongitude)和地点(placeLatitude/placeLongitude)之间的距离.我的坐标存储为NSStrings,如下所示.有谁知道如何做到这一点?谢谢你们!
NSString *userLatitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate
getUserLatitude];
NSString *userLongitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate
getUserLongitude];
NSString *placeLatitude = [element1 objectForKey:@"placeLatitude"];
NSString *placeLongitude = [element1 objectForKey:@"placeLongitude"];
Run Code Online (Sandbox Code Playgroud) 我的应用监控用户位置,包括一些后台位置监控.
我的App Delegate中有一个位置管理器,主要用于初始启动位置以及后台更新.然后我在视图控制器(地图)中有另一位经理,以获取更具体的事件和快速参考.
我想知道将这个重构为一个实例,保存在App Delegate中,并在整个应用程序中使用以下内容引用它是一个好习惯:
self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self.appDelegate.locationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud) 我试图获得用户的纬度和经度,但我得到了结果0.000000 - 我尝试了以下代码.
码:
locationmanager=[[CLLocationManager alloc]init];
locationmanager.delegate=self;
// check before requesting, otherwise it might crash in older version
if ([locationmanager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationmanager requestWhenInUseAuthorization];
}
[locationmanager startUpdatingLocation];
#pragma mark - CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"locations %@",locations);
CLLocation*location = [locations lastObject];
NSLog(@"location %f",location.coordinate.latitude);
}
Run Code Online (Sandbox Code Playgroud)
结果:2014-10-15 11:10:20.118好[714:25676]纬度0.000000
我正在开发一个应用程序,用户可以在其中设置多个位置。当用户获得Enter或离开特定位置边界时,我成功显示通知。
现在,有些情况下我需要为所有保存的位置提供监视,并且可能有数百个甚至更多。我在Apple论坛上读过很多文章,其中许多iOS设备仅允许20个区域监视。

我已经开发了我的代码以超出这种情况。我已经设置locationManager.distanceFilter = 200; 当我获得位置更新时。首先,我已停止所有区域监视,并按最近位置的条件停止运行,然后再次启动20个已保存位置的区域监视。
我认为上述解决方案可能会导致在停止并再次重新启动区域监视时丢失任何已保存的位置。因此,请提供给我其他更好的解决方案,以解决仅20条有关“区域监视”问题的通知。
祝你今天愉快 。!!..
在设置应用程序>隐私>位置服务>我的应用程序>从不在后台模式下,didChangeAuthorizationStatus被称为kCLAuthorizationStatusDenied状态.但在更改"Always"之后,未调用didChangeAuthorizationStatus.关闭"位置服务"时也不会调用.
我在Info.plist中插入了NSLocationAlwaysUsageDescription并设置了位置更新后台模式.
我的代码,
- (id)init {
self = [super init];
if (self) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.pausesLocationUpdatesAutomatically = NO;
if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
NSLog(@"setAllowsBackgroundLocationUpdates");
_locationManager.allowsBackgroundLocationUpdates = YES;
}
[self requestAuthorization];
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
NSLog(@"CLAuthorizationStatus: %d", status);
}
Run Code Online (Sandbox Code Playgroud)
对不起我的英文.
我已经在swift 3中整合了谷歌地图,当地图画面出现时没有显示当前位置,我在.plist文件中添加了两个键,还设置了CLLocationManager委托和requestAlwaysAuthorization
class MapViewController: UIViewController, CLLocationManagerDelegate, UITextFieldDelegate {
@IBOutlet var mapView: GMSMapView!
var marker: GMSMarker?
override func viewDidLoad() {
super.viewDidLoad()
self.title = "MapVC"
self.doSetupUI()
self.searchLocation()
}
override func viewWillAppear(_ animated: Bool) {
let locationManager : CLLocationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
}
func doGoogleMapSetup(lat : Double , lng : Double) {
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude:lng, zoom:16)
let mapView = GMSMapView.map(withFrame: .zero, camera:camera)
mapView.isMyLocationEnabled = true
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: lat, longitude: lng)
marker.snippet = …Run Code Online (Sandbox Code Playgroud) ios ×7
objective-c ×4
iphone ×3
cllocation ×1
dictionary ×1
google-maps ×1
ios6 ×1
ios8 ×1
location ×1
nsstring ×1
swift ×1
swift3 ×1
xcode ×1