我具有利用LocationManager
进行iOS开发的功能。该函数实现了非常普遍的目的,即从LocationManager
对象中提取纬度和经度,并填充一些方法变量以构建一组方向。
目前,当存在一些专门放置的断点时,该方法在iOS模拟器上可以正常工作。我将逐步进入每个步骤,直到看到lat和long已填充完毕,然后继续执行程序。正确更改了视图以显示一组方向。
但是,如果删除了断点,则永远不会填充变量,并且纬度和经度的视图默认为0.000
。
我还看到其中一个线程出错(我完全不熟悉基于线程的编程。这不是我正在调试的应用程序:Thread 1: EXC_BAD_ACCESS (CODE =1, address= {some address}
] >>
下面是功能代码(asdf
只是LocationManager
的实例名称):
(void)webViewDidFinishLoad:(UIWebView *)webView
{
asdf = [[CLLocationManager alloc] init];
asdf.delegate = self;
asdf.distanceFilter = kCLDistanceFilterNone;
asdf.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[asdf startUpdatingLocation];
CLLocation *location = [asdf location];
float longitude=location.coordinate.longitude;
float latitude=location.coordinate.latitude;
NSLog(@"dLongitude : %f", longitude);
NSLog(@"dLatitude : %f", latitude);
double userLatitude = latitude;
double userLongitude = longitude;
[locationManager stopUpdatingLocation];
NSString *userLat = [NSString stringWithFormat:@"%f", userLatitude];
NSString *userLng = [NSString stringWithFormat:@"%f", userLongitude];
NSString *destinationLatitude = site.siteGPSN;
NSString *destinationLongitude = site.siteGPSW;
NSString *javascriptString = [NSString stringWithFormat:@"buildMap('%@','%@','%@','%@')",destinationLatitude, destinationLongitude, userLat, userLng];
[webView stringByEvaluatingJavaScriptFromString:javascriptString];
}
我有一个利用LocationManager进行iOS开发的功能。该函数实现了非常普遍的目的,即从LocationManager对象中提取经度和纬度并填充一些...
您没有正确使用CLLocationManager
。您需要实现CLLocationManagerDelegate
。否则,不能保证管理器在尝试使用location
对象时会对其进行缓存。
位置管理器永远不会在您使用startUpdatingLocation
启动更新后立即获得更新,这是委托方法生效的时候。仅当位置更新可用或过程由于某种原因而失败时,才调用委托方法。