Ios CLLocationManager请求位置为';不要打电话给didUpdateLocations
我试图使用Ios CLLocationManager请求位置为';不要打电话给didUpdateLocations,ios,objective-c,iphone,cocoa-touch,core-location,Ios,Objective C,Iphone,Cocoa Touch,Core Location,我试图使用[self.locationManager requestLocation]获取当前用户位置,但由于某些原因,没有调用委托方法locationManager:didUpdateLocations: 我正在从UIButton(IBOutlet)处理程序调用requestLocation 知道为什么吗 谢谢大家! 右键单击info.plist open as-->源代码将以下代码添加到… NSLocationAlwaysUsageDescription 应用程序希望使用您的位置。 NSLo
[self.locationManager requestLocation]
获取当前用户位置,但由于某些原因,没有调用委托方法locationManager:didUpdateLocations:
我正在从UIButton
(IBOutlet
)处理程序调用requestLocation
知道为什么吗
谢谢大家! 右键单击info.plist open as-->源代码将以下代码添加到
…
NSLocationAlwaysUsageDescription
应用程序希望使用您的位置。
NSLocationUsageDescription
我需要位置
NSLocationWhenUse用途说明
应用程序希望使用您的位置。
UIMainstryBoardFile
进口
然后调用CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manage
didUpdateLocations:(NSArray *)locations
{
CLLocation *currentAction = [locations objectAtIndex:0];
CLLocation *crnLoc = [locations lastObject];
[self.locationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// If the event is recent, do something with it.
NSLog(@"latitude~~~: %+.8f, longitude~~~: %+.8f\n",
location.coordinate.latitude,
location.coordinate.longitude);
self.latitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.latitude];
self.longitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.longitude];
}
self.latitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.latitude];
self.longitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.longitude];
[geocoder reverseGeocodeLocation:currentAction
completionHandler:^(NSArray *placemarks, NSError *error)
{
if (!(error))
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSString *locatedAt = [[placemark.addressDictionary
valueForKey:@"FormattedAddressLines"]
componentsJoinedByString:@", "];
NSString *Address = [[NSString alloc]initWithString:locatedAt];
NSLog(@"Adress %@",Address);
}
else
{
NSLog(@"\n Current Location Not Detected \n");
return;
}
}];
}
-(无效)locationManager:(CLLocationManager*)管理
didUpdateLocations:(NSArray*)位置
{
CLLocation*currentAction=[locations objectAtIndex:0];
CLLocation*crnLoc=[locations lastObject];
[self.locationManager停止更新位置];
CLGeocoder*geocoder=[[CLGeocoder alloc]init];
CLLocation*location=[locations lastObject];
NSDate*eventDate=location.timestamp;
NSTimeInterval howRecent=[eventDate timeIntervalSinceNow];
如果(abs(最近几年)<15.0){
//如果这件事是最近发生的,那就做点什么吧。
NSLog(@“纬度~~~:%+.8f,经度~~:%+.8f\n”,
位置坐标纬度,
位置、坐标、经度);
self.latitudeLabel.text=[NSString stringWithFormat:@“%.8f”,
坐标纬度];
self.longitudeLabel.text=[NSString stringWithFormat:@“%.8f”,
坐标经度];
}
self.latitudeLabel.text=[NSString stringWithFormat:@“%.8f”,
坐标纬度];
self.longitudeLabel.text=[NSString stringWithFormat:@“%.8f”,
坐标经度];
[地理编码器反向地理位置:currentAction
completionHandler:^(NSArray*放置标记,NSError*错误)
{
如果(!(错误))
{
CLPlacemark*placemark=[placemarks objectAtIndex:0];
NSString*locatedAt=[[placemark.addressDictionary
valueForKey:@“FormattedAddressLines”]
组件通过字符串连接:@“,”];
NSString*地址=[[NSString alloc]initWithString:locatedAt];
NSLog(@“地址%@”,地址);
}
其他的
{
NSLog(@“\n未检测到当前位置\n”);
返回;
}
}];
}
希望此代码对您有所帮助。右键单击info.plist open as-->源代码将以下代码添加到
..
NSLocationAlwaysUsageDescription
应用程序希望使用您的位置。
NSLocationUsageDescription
我需要位置
NSLocationWhenUse用途说明
应用程序希望使用您的位置。
UIMainstryBoardFile
进口
然后调用CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manage
didUpdateLocations:(NSArray *)locations
{
CLLocation *currentAction = [locations objectAtIndex:0];
CLLocation *crnLoc = [locations lastObject];
[self.locationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// If the event is recent, do something with it.
NSLog(@"latitude~~~: %+.8f, longitude~~~: %+.8f\n",
location.coordinate.latitude,
location.coordinate.longitude);
self.latitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.latitude];
self.longitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.longitude];
}
self.latitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.latitude];
self.longitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.longitude];
[geocoder reverseGeocodeLocation:currentAction
completionHandler:^(NSArray *placemarks, NSError *error)
{
if (!(error))
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSString *locatedAt = [[placemark.addressDictionary
valueForKey:@"FormattedAddressLines"]
componentsJoinedByString:@", "];
NSString *Address = [[NSString alloc]initWithString:locatedAt];
NSLog(@"Adress %@",Address);
}
else
{
NSLog(@"\n Current Location Not Detected \n");
return;
}
}];
}
-(无效)locationManager:(CLLocationManager*)管理
didUpdateLocations:(NSArray*)位置
{
CLLocation*currentAction=[locations objectAtIndex:0];
CLLocation*crnLoc=[locations lastObject];
[self.locationManager停止更新位置];
CLGeocoder*geocoder=[[CLGeocoder alloc]init];
CLLocation*location=[locations lastObject];
NSDate*eventDate=location.timestamp;
NSTimeInterval howRecent=[eventDate timeIntervalSinceNow];
如果(abs(最近几年)<15.0){
//如果这件事是最近发生的,那就做点什么吧。
NSLog(@“纬度~~~:%+.8f,经度~~:%+.8f\n”,
位置坐标纬度,
位置、坐标、经度);
self.latitudeLabel.text=[NSString stringWithFormat:@“%.8f”,
坐标纬度];
self.longitudeLabel.text=[NSString stringWithFormat:@“%.8f”,
坐标经度];
}
self.latitudeLabel.text=[NSString stringWithFormat:@“%.8f”,
坐标纬度];
self.longitudeLabel.text=[NSString stringWithFormat:@“%.8f”,
坐标经度];
[地理编码器反向地理位置:currentAction
completionHandler:^(NSArray*放置标记,NSError*错误)
{
如果(!(错误))
{
CLPlacemark*placemark=[placemarks objectAtIndex:0];
NSString*locatedAt=[[placemark.addressDictionary
valueForKey:@“FormattedAddressLines”]
组件通过字符串连接:@“,”];
NSString*地址=[[NSString alloc]initWithString:locatedAt];
NSLog(@“地址%@”,地址);
}
其他的
{
NSLog(@“\n未检测到当前位置\n”);
返回;
}
}];
}
希望此代码对您有所帮助。我认为您的问题与
如果要将
CLLocationManager
实例创建为函数级实例,则该实例将在函数完成后的某个时间点(可能在调用委托之前)取消分配。如果改为将其创建为类级实例,将调用委托,因为CLLocationManager
实例仍然存在。我认为您的问题与
如果要将
CLLocationManager
实例创建为函数级实例,则该实例将在函数完成后的某个时间点(可能在调用委托之前)取消分配。如果将其创建为类级实例,则将调用委托,因为CLLocationManager
实例仍将存在。您是否在Info.plist
文件中设置了nsLocationWhenUsageDescription
和NSLocationAlwaysUsageDescription
时设置了NSLocationAlwaysUsageDescription
?是否已启用应用程序以接收位置iOS设置中的信息?“允许此应用接收位置信息..'etcare您添加了locationManager.delegate=self
在您当前的类中,您是否在Info.plist
文件中设置了nslocationwhenUsageDescription
和NSLocationAlwaysUsageDescription
时的位置?只需NSLocationAlwaysUsageDescription
尝试设置另一个。Hav
- (void)locationManager:(CLLocationManager *)manage
didUpdateLocations:(NSArray *)locations
{
CLLocation *currentAction = [locations objectAtIndex:0];
CLLocation *crnLoc = [locations lastObject];
[self.locationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// If the event is recent, do something with it.
NSLog(@"latitude~~~: %+.8f, longitude~~~: %+.8f\n",
location.coordinate.latitude,
location.coordinate.longitude);
self.latitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.latitude];
self.longitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.longitude];
}
self.latitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.latitude];
self.longitudeLabel.text=[NSString stringWithFormat:@"%.8f",
crnLoc.coordinate.longitude];
[geocoder reverseGeocodeLocation:currentAction
completionHandler:^(NSArray *placemarks, NSError *error)
{
if (!(error))
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSString *locatedAt = [[placemark.addressDictionary
valueForKey:@"FormattedAddressLines"]
componentsJoinedByString:@", "];
NSString *Address = [[NSString alloc]initWithString:locatedAt];
NSLog(@"Adress %@",Address);
}
else
{
NSLog(@"\n Current Location Not Detected \n");
return;
}
}];
}