相关疑难解决方法(0)

iOS:应用程序在安装应用程序时不会询问用户的权限.每次都得到kCLAuthorizationStatusNotDetermined - Objective-c&Swift

我正在尝试在我的iOS应用中获取用户位置.我首先在我的项目中包含了重置框架.然后在按钮上单击我调用核心位置api,如下所示.当我尝试在设备中安装它时,核心位置永远不会询问用户权限.当我尝试在按钮单击时获取位置时,我将获得kCLAuthorizationStatusNotDetermined作为authorisationStatus.请帮帮我.我不知道发生了什么.

- (IBAction)fetchLessAccurateLocation:(id)sender {
    [self.txtLocation setText:@""];

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    locationManager.distanceFilter = 1000;

    if ([self shouldFetchUserLocation]) {
        [locationManager startUpdatingLocation];
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的shouldFetchUserLocation方法:

-(BOOL)shouldFetchUserLocation{

    BOOL shouldFetchLocation= NO;

    if ([CLLocationManager locationServicesEnabled]) {
        switch ([CLLocationManager authorizationStatus]) {
            case kCLAuthorizationStatusAuthorized:
                shouldFetchLocation= YES;
                break;
            case kCLAuthorizationStatusDenied:
            {
                UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Error" message:@"App level settings has been denied" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                [alert show];
                alert= nil;
            }
                break;
            case kCLAuthorizationStatusNotDetermined:
            {
                UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Error" message:@"The user is yet …
Run Code Online (Sandbox Code Playgroud)

gps core-location cllocationmanager ios

70
推荐指数
6
解决办法
9万
查看次数

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

在我的viewDidLoad方法中,我有

locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
locationManager.delegate = self; // we set the delegate of locationManager to self.
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];


if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    [locationManager requestWhenInUseAuthorization];
}
Run Code Online (Sandbox Code Playgroud)

并且调用了请求,但是没有提示用户?为什么?

xcode objective-c cllocationmanager ios8

69
推荐指数
1
解决办法
6万
查看次数

iOS 8 Map Kit Obj-C无法获取用户位置

我使用Obj-C NOT SWIFT在iOS 8中使用Map Kit.我无法获得它设置的设备位置0.00,0.00,我收到错误:

Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
Run Code Online (Sandbox Code Playgroud)

我实施了:(我一次只试过一次,没有运气)

if(IS_OS_8_OR_LATER) {
    [self.locationManager requestWhenInUseAuthorization];
    [self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation]; 
Run Code Online (Sandbox Code Playgroud)

并在info.plist中

NSLocationWhenInUseUsageDescription  :   App would like to use your location.
NSLocationAlwaysUsageDescription  :  App would like to use your location.
Run Code Online (Sandbox Code Playgroud)

我得到提示允许应用程序使用我的位置,但在我同意没有任何变化.该位置显示为0.00,0.00.

显示用户位置的代码:

//Get Location
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];

MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, …
Run Code Online (Sandbox Code Playgroud)

objective-c mapkit cllocationmanager ios8

51
推荐指数
2
解决办法
5万
查看次数

CLLocationManager startUpdatingLocation不调用locationManager:didUpdateLocations:或locationManager:didFailWithError:

我正在尝试使用CLLocationManager我的iOS项目中的框架来访问用户的位置,但是当我打电话时

[locationManager startUpdatingLocation]
Run Code Online (Sandbox Code Playgroud)

既不locationManager:didUpdateLocations:locationManager:didFailWithError:越来越调用.

//myViewController.h
@interface myViewController : UITableViewController <CLLocationManagerDelegate>
@end

//myViewController.m
@implementation myViewController{
    CLLocationManager *locationManager;
}

//edit
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
}
//finish edit

-(void)getLocation
{
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
UIAlertView *errorAlert = [[UIAlertView alloc]
                           initWithTitle:@"Error" 
                                 message:@"Failed to Get Your Location"              
                                delegate:nil 
                       cancelButtonTitle:@"OK" 
                      otherButtonTitles:nil];
[errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *newLocation = …
Run Code Online (Sandbox Code Playgroud)

objective-c cllocationmanager ios

37
推荐指数
4
解决办法
4万
查看次数

Swift - 将MKAnnotationView添加到MKMapView

我想加入MKAnnotationView,MKMapView但我不能这样做......任何人都可以帮助我吗?

这是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.startUpdatingLocation()
    var latitude:CLLocationDegrees = locationManager.location.coordinate.latitude
    var longitude:CLLocationDegrees = locationManager.location.coordinate.longitude
    var homeLati: CLLocationDegrees = 40.01540192
    var homeLong: CLLocationDegrees = 20.87901079
    var latDelta:CLLocationDegrees = 0.01
    var longDelta:CLLocationDegrees = 0.01
    var theSpan:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
    var myHome:CLLocationCoordinate2D = CLLocationCoordinate2DMake(homeLati, homeLong)
    var myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
    var theRegion:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, theSpan)
    self.theMapView.setRegion(theRegion, animated: true)
    self.theMapView.mapType = MKMapType.Hybrid
    self.theMapView.showsUserLocation = true
    ///Red Pin
    var myHomePin = MKPointAnnotation()
    myHomePin.coordinate = myHome
    myHomePin.title …
Run Code Online (Sandbox Code Playgroud)

mkmapview mkannotation mkannotationview swift

24
推荐指数
1
解决办法
4万
查看次数

核心位置委托方法未在iOS 8.3 Xcode 6.3.1中调用

我试图使用Xcode 6.3.1中的核心位置框架获取用户的当前位置,我做了以下事情:

  1. Target - > General - > Linked Frameworks&Libraries下添加了Core Location Framework
  2. 我的ViewController.h文件如下所示,

    #import <UIKit/UIKit.h>
    #import <CoreLocation/CoreLocation.h>
    
    @interface ViewController : UIViewController<CLLocationManagerDelegate>
    @property (weak, nonatomic) IBOutlet UILabel *lblLatitude;
    @property (weak, nonatomic) IBOutlet UILabel *lblLongitude;
    @property (weak, nonatomic) IBOutlet UILabel *lblAddress;
    @property (strong, nonatomic) CLLocationManager *locationManager;
    
    @end
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我的ViewController.m文件如下所示,

    - (void)viewDidLoad
    {
    
    [super viewDidLoad];
    self.locationManager = [[CLLocationManager alloc] init];
    
    self.locationManager.delegate = self;
    if(IS_OS_8_OR_LATER){
        NSUInteger code = [CLLocationManager authorizationStatus];
        if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) …
    Run Code Online (Sandbox Code Playgroud)

core-location ios ios8.3 xcode6.3.1

15
推荐指数
1
解决办法
1691
查看次数

Google Maps API:获取当前位置iOS的坐标

我目前正在我的项目中使用Google Maps API.我正在尝试将默认相机/缩放设置为用户位置.我这样做:

@implementation ViewController{

GMSMapView *mapView_;

}
@synthesize currentLatitude,currentLongitude;

- (void)viewDidLoad
{
[super viewDidLoad];
mapView_.settings.myLocationButton = YES;
mapView_.myLocationEnabled = YES;


}
- (void)loadView{

CLLocation *myLocation = mapView_.myLocation;

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(myLocation.coordinate.latitude, myLocation.coordinate.longitude);
marker.title = @"Current Location";
marker.map = mapView_;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:myLocation.coordinate.latitude
                                                        longitude:myLocation.coordinate.longitude
                                                             zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];

self.view = mapView_;
   NSLog(@"%f, %f", myLocation.coordinate.latitude, myLocation.coordinate.longitude);

}
Run Code Online (Sandbox Code Playgroud)

但是,它不起作用,因为当我这样做

NSLog(@"%f, %f", myLocation.coordinate.latitude, myLocation.coordinate.longitude);
Run Code Online (Sandbox Code Playgroud)

它返回0,0,并且它不给出当前位置坐标.如何正确获取用户的坐标?

location google-maps objective-c ios google-maps-sdk-ios

9
推荐指数
2
解决办法
4万
查看次数

Xcode 6/iOS 8位置模拟不起作用

我刚刚更新到Xcode 6/iOS 8 SDK,我在模拟器中的位置服务模拟开始不起作用.我更新之前很好(我目前无法在真实设备上测试).现在,当我选择一个模拟位置时,没有任何反应.-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations不调用Delegate的方法.我重新启动了Xcode,清理了构建文件夹,没有任何改变.为什么会这样?

xcode ios xcode6 ios8

8
推荐指数
2
解决办法
1万
查看次数

如何在IOS SDK 8.0中获取当前位置的经度和纬度

如何获取当前位置的经纬度.

我试过这个.使用Xcode 6.01和IOS SDK 8.0

-(CLLocationCoordinate2D) getLocation{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    [locationManager startUpdatingLocation];
    CLLocation *location = [locationManager location];
    CLLocationCoordinate2D coordinate = [location coordinate];
    return coordinate;
}

- (void)getCurrentLocation{    
    CLLocationCoordinate2D coordinate = [self getLocation];
    NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
    NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
    NSLog(@"Latitude  = %@", latitude);
    NSLog(@"Longitude = %@", longitude);
}


- (void)viewDidLoad{
    [super viewDidLoad];
    [self getCurrentLocation];

}
Run Code Online (Sandbox Code Playgroud)

在这里,我将模拟器位置启用到Deployment 8.0 iPhone模拟器4s.即使在设备上也无法正常工作.

@ALL请告诉我,我在这里做错了什么.

core-location cllocationmanager cllocation currentlocation ios8

8
推荐指数
2
解决办法
1万
查看次数

在iOS 8上本地化用户

Hullo,我开始将我的应用程序移植到iOS 8,我很快就陷入了CLLocationManager的问题.基本上,应用程序不再将地图集中在用户的位置上,而是提出错误:

尝试在不提示位置授权的情况下启动MapKit位置更新.必须首先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization].

执行

 [CLLocationManager requestAlwaysAuthorization]
Run Code Online (Sandbox Code Playgroud)

什么都不做,甚至NSLocationAlwaysUsageDescription在应用程序的Info.plist中插入 密钥几乎没有变化.实际上,操作的唯一明显效果是首选项中的位置设置,在运行应用程序时,其值已从我输入的值重置.

cllocationmanager ios8

7
推荐指数
2
解决办法
5812
查看次数