草庐IT

LocationManager

全部标签

android - 如何在 Fragment 中获取对 LocationManager 的引用

我有一个扩展Fragment并实现LocationListener的类。当我写LocationManagermyLocalManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);我得到一个编译时错误,因为方法getSystemService不是Fragment的方法。为了创建LocationManager,我该怎么做? 最佳答案 在你的fragment中简单地调用这个:LocationManagermgr=(LocationManager)getActi

android - 如何使用 locationManager(GPS 和 NETWORK PROVIDER)只读取一次位置,而不再寻找位置更新?

如何使用locationManager(GPS和NETWORKPROVIDER)只读取一次位置,而不再寻找位置更新以节省电池? 最佳答案 虽然requestSingleUpdate()是技术上正确的答案,但您应该使用locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,1,mLocationListener);获得第一个位置后稍等片刻。该位置往往会摇晃几秒钟。要确定修复是否稳定使用,location.getAccuracy()。准确度稳定后,

android - LocationManager 的 getBestProvider 返回 null

我有很多人报告了一个我无法重现的错误。当尝试打开MapView它报告getBestProvider正在返回null并且我知道这意味着没有找到满足我的标准的提供程序ACCURACY_COARSE因此,如果没有GPS,那么它应该依靠network或被动但显然不在那些用户设备上。如果GPS已关闭且没有网络连接,这意味着什么?我尝试关闭GPS并将手机置于飞行模式以尝试重现该问题,但我仍然能够在不强制关闭的情况下打开mapView,因此我不知道如何处理此问题。locationManager=(LocationManager)this.getSystemService(LOCATION_SERVI

ios - CLLocationManager startUpdatingLocation 未调用 locationManager :didUpdateLocations: or locationManager:didFailWithError:

我试图在我的iOS项目中使用CLLocationManager框架来访问用户的位置,但是当我调用时[locationManagerstartUpdatingLocation]locationManager:didUpdateLocations:或locationManager:didFailWithError:都没有被调用。//myViewController.h@interfacemyViewController:UITableViewController@end//myViewController.m@implementationmyViewController{CLLocatio

objective-c - 为什么 requestWhenInUseAuthorization 不提示用户访问该位置?

在我的viewDidLoad方法中,我有locationManager=[[CLLocationManageralloc]init];//initializinglocationManagerlocationManager.delegate=self;//wesetthedelegateoflocationManagertoself.locationManager.desiredAccuracy=kCLLocationAccuracyBest;[locationManagerstartUpdatingLocation];if([[[UIDevicecurrentDevice]syste

objective-c - 为什么 requestWhenInUseAuthorization 不提示用户访问该位置?

在我的viewDidLoad方法中,我有locationManager=[[CLLocationManageralloc]init];//initializinglocationManagerlocationManager.delegate=self;//wesetthedelegateoflocationManagertoself.locationManager.desiredAccuracy=kCLLocationAccuracyBest;[locationManagerstartUpdatingLocation];if([[[UIDevicecurrentDevice]syste

ios - 定期 iOS 后台位置更新

我正在编写一个需要以高精度和低频率进行后台位置更新的应用程序。解决方案似乎是一个后台NSTimer任务,它启动位置管理器的更新,然后立即关闭。之前有人问过这个问题:HowdoIgetabackgroundlocationupdateeverynminutesinmyiOSapplication?GettinguserlocationeverynminutesafterappgoestobackgroundiOSNotthetypicalbackgroundlocationtrackingtimerissueiOSlong-runningbackgroundtimerwith"locat

ios - 定期 iOS 后台位置更新

我正在编写一个需要以高精度和低频率进行后台位置更新的应用程序。解决方案似乎是一个后台NSTimer任务,它启动位置管理器的更新,然后立即关闭。之前有人问过这个问题:HowdoIgetabackgroundlocationupdateeverynminutesinmyiOSapplication?GettinguserlocationeverynminutesafterappgoestobackgroundiOSNotthetypicalbackgroundlocationtrackingtimerissueiOSlong-runningbackgroundtimerwith"locat

ios - 如何在 iOS 中从用户那里获取当前位置

如何在iOS中从用户那里获取当前位置? 最佳答案 RedBlueThing的答案对我来说效果很好。这是我如何做到的一些示例代码。标题#import#import@interfaceyourController:UIViewController{CLLocationManager*locationManager;}@end主文件在init方法中locationManager=[[CLLocationManageralloc]init];locationManager.delegate=self;locationManager.dist

ios - 如何在 iOS 中从用户那里获取当前位置

如何在iOS中从用户那里获取当前位置? 最佳答案 RedBlueThing的答案对我来说效果很好。这是我如何做到的一些示例代码。标题#import#import@interfaceyourController:UIViewController{CLLocationManager*locationManager;}@end主文件在init方法中locationManager=[[CLLocationManageralloc]init];locationManager.delegate=self;locationManager.dist