我正在使用CoreLocation并从我的应用程序AppDelegate中启动locationManager.示例代码如下......
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...
// start location manager
if([CLLocationManager locationServicesEnabled])
{
myLocationManager_ = [[CLLocationManager alloc] init];
myLocationManager_.delegate = self;
[myLocationManager_ startUpdatingLocation];
}
else
{
// ... rest of code snipped to keep this short
Run Code Online (Sandbox Code Playgroud)
在这种方法中,我们看到更新的位置.
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSString *currentLatitude = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
NSLog(@"AppDelegate says: latitude: %@", currentLatitude);
// ... rest of code snipped
Run Code Online (Sandbox Code Playgroud)
现在,在我的应用程序的其他区域中,我需要确定用户当前位置(纬度,经度).我可以结合上面的代码到需要当前位置的ViewControllers但后来我不得不CLLocationManager的多个实例运行(我认为) - 为什么复制此代码?有没有办法,从其他ViewControllers,我可以从AppDelegate获取位置信息?
PS - 我正在使用Xcode 4.3 w/ARC
iphone objective-c core-location cllocationmanager cllocation
要清楚我的问题是没有在横向或左边读取横向的标题值.它运行正常我正在使用位置管理器并减去90°来读取横向右侧的标题值和左侧的270°,默认情况下设备始终被视为纵向模式,这就是我们必须进行此调整的原因.
我最近开发了一个基于位置的增强现实应用程序,我正在经历的是,左右横向之间的标题值始终存在偏移.我在"现场"测试,偏移约为12°.
我希望这个应用程序尽可能准确,我的意思是因为我们依赖于传感器数据,这是第一个版本,小于10°是可以接受的(在最坏的情况下甚至是15°).但是如果我们将现有误差添加到12°的偏移量,那就非常烦人了.
有没有人对此有解释?即使我现在无法修复它,我也希望有一个.所以现在我试图通过向左侧的景观添加12°来"修复"这个,或者我可能宁愿减去12°到景观,我不知道!
有关这个问题的经验吗?
我正在使用iPhone应用程序,CLLocationManager用于开发我的应用程序,当我运行应用程序时,它显示一个警报视图,如"想要使用您当前的位置".然后prees Ok继续它.
但我不想显示警报视图,是否可以让应用程序在没有提示的情况下跟踪用户的位置?
提前致谢

我有两点CLLocationCoordinate2D,让我们说A&B mapView.我想要一个箭头图像从一个点指向另一个点(A-> B).我无法找到transform箭头图像的正确角度.
请参阅此图片以供参考 
提前致谢.
甚至我的应用程序都在后台注册位置更新.
在我的代码中:
self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
self.locationManager.distanceFilter = 2500;
Run Code Online (Sandbox Code Playgroud)
我没有搬到任何地方.因此,在控制台日志中完成15分钟后,我收到此消息"位置图标现在应处于"非活动状态".从这一点开始,我的应用程序不在后台运行.
它只在iPhone 5中发生.
@更新
这是我的代码
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager setPurpose:@"Enable Location service for \"My App\" to track your"];
self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
/* Notify changes when device has moved x meters.
* Default value is kCLDistanceFilterNone: all movements are reported.
*/
self.locationManager.distanceFilter = 2500;
[self.locationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud) 我需要使用CLGeocoder 而不是 Google API 对大量地址进行地理编码.
我的问题是我的代码只为下面数组中的第一个地址添加了注释.但是,函数被调用适当的次数 - 在为所有地址调用函数之后,块只运行第一个地址:
- (void)mapPoints {
NSString *foo = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"names%d", self.indexOfSchool] ofType:@"plist"];
NSArray *description = [NSArray arrayWithContentsOfFile:foo];
NSString *bar = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d1", self.indexOfSchool] ofType:@"plist"];
NSArray *details = [NSArray arrayWithContentsOfFile:bar];
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d0", self.indexOfSchool] ofType:@"plist"];
NSArray *addresses = [NSArray arrayWithContentsOfFile:path];
self.saved = [NSMutableArray alloc] init];
for (int q = 0; q < addresses.count; q+= 20) {
[self annotate:[addresses objectAtIndex:q] detail:[details objectAtIndex:q] andDesc:[description objectAtIndex:q]];
}
}
see updated …Run Code Online (Sandbox Code Playgroud) 好的,所以我目前有一个应用程序,我在其中注册使用该CLLocationManager startMonitoringForRegion方法监控的地理围栏.当应用程序位于前台和后台时,此工作正常.
我也有适当的plist值设置:
UIBackgroundModes :{location}
UIRequiredDeviceCapabilities: {location-services}
Run Code Online (Sandbox Code Playgroud)
设备重启后,应用程序未重新启动.如果我startMonitoringSignificantLocationChanges在进入背景之前设置,我可以强制这种情况发生.但是这种方法使用了更多的电池寿命,而且我不需要这个位置,就在我打破地理围栏的时候.
各地区的文件说:
In iOS, the regions you register with the location manager persist between launches of your application. If a region crossing occurs while your iOS app is not running, the system automatically wakes it up (or relaunches it) in the background so that it can process the event. When relaunched, all of the regions you configured previously are made available in the monitoredRegions property of any location …
我在我的方法didUpdateLocations中获得用户的经度和经度.如果允许位置,我调用一个接受纬度,经度参数并调用webservice的方法,否则我会显示一个UIAlertView.
问题是:iOS随机调用我的locationManager委托方法.所以我的网络服务被多次调用......我该如何解决?
当我呼叫该位置时,验证是否允许...我在上一个屏幕中发出请求:
// GET LOCATION
self.initializeWaitingScreen()
if( CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedWhenInUse ||
CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedAlways){
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.startUpdatingLocation()
} else {
let loginFailAlert: UIAlertView = UIAlertView(title: "Localisation refusée", message: "Vos fonctionnalités sont restreintes, pour accéder à l'application complète, veuillez activer la localisation", delegate: self, cancelButtonTitle: "OK")
loginFailAlert.show()
self.initializeUIComponent()
self.initializeDataWithWebServiceWithoutLocation()
}
Run Code Online (Sandbox Code Playgroud)
我的locationManager方法:
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
var lon = manager.location.coordinate.longitude.description
var lat = manager.location.coordinate.latitude.description
self.locationManager.stopUpdatingLocation()
self.initializeDataWithWebServiceWithLocation(lon, _lat: lat)
self.initializeUIComponent()
}
Run Code Online (Sandbox Code Playgroud)
self.initializeDataWithWebServiceWithLocation(lon, _lat: lat)
取经度和纬度,并将其交给我调用webservices的方法.
当我开始监视像这样的地区时
locationManager.startMonitoringForRegion(tGeoFence[wert][wert2])
Run Code Online (Sandbox Code Playgroud)
并尝试确定它是否已经在此之后输入:
for region in locationManager.monitoredRegions {
if let cireg = region as? CLCircularRegion {
if cireg.identifier == tGeoFence[wert][wert2].identifier {
locationManager.requestStateForRegion(cireg)
}
}
}
Run Code Online (Sandbox Code Playgroud)
不起作用,导致在执行代码的第二部分时未完成区域的注册.延迟该部分的执行似乎很难看(确定并不总是被调用),有没有更好的方法来解决这个问题?
我正在尝试计算2个坐标之间的距离.为此我做:
func setupLocationManager() {
if CLLocationManager.authorizationStatus() == .NotDetermined {
locationManager.requestWhenInUseAuthorization()
}
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let latitude = locations.last?.coordinate.latitude
let longitude = locations.last?.coordinate.longitude
let myLocation = CLLocation(latitude: latitude!, longitude: longitude!)
let targetLocation = CLLocation(latitude: 41.4381022, longitude: 46.604910)
let distance = myLocation.distanceFromLocation(targetLocation)
print(distance)
}
Run Code Online (Sandbox Code Playgroud)
我正在检查谷歌地图有13公里的距离!但我的应用程序显示我2-3公里!
我怎样才能改善这一点?
ios ×7
objective-c ×3
cllocation ×2
iphone ×2
swift ×2
coordinates ×1
geofencing ×1
mapkit ×1
mkmapview ×1
swift2 ×1
uialertview ×1