• <legend id='EVkuf'><style id='EVkuf'><dir id='EVkuf'><q id='EVkuf'></q></dir></style></legend>

    <small id='EVkuf'></small><noframes id='EVkuf'>

    <i id='EVkuf'><tr id='EVkuf'><dt id='EVkuf'><q id='EVkuf'><span id='EVkuf'><b id='EVkuf'><form id='EVkuf'><ins id='EVkuf'></ins><ul id='EVkuf'></ul><sub id='EVkuf'></sub></form><legend id='EVkuf'></legend><bdo id='EVkuf'><pre id='EVkuf'><center id='EVkuf'></center></pre></bdo></b><th id='EVkuf'></th></span></q></dt></tr></i><div id='EVkuf'><tfoot id='EVkuf'></tfoot><dl id='EVkuf'><fieldset id='EVkuf'></fieldset></dl></div>
      <bdo id='EVkuf'></bdo><ul id='EVkuf'></ul>
    <tfoot id='EVkuf'></tfoot>

      1. Mac 上的 iOS 7 模拟器不适用于自定义位置(也不会

        时间:2023-09-01

                  <bdo id='NinaO'></bdo><ul id='NinaO'></ul>
                  <legend id='NinaO'><style id='NinaO'><dir id='NinaO'><q id='NinaO'></q></dir></style></legend>

                • <tfoot id='NinaO'></tfoot>

                  <small id='NinaO'></small><noframes id='NinaO'>

                • <i id='NinaO'><tr id='NinaO'><dt id='NinaO'><q id='NinaO'><span id='NinaO'><b id='NinaO'><form id='NinaO'><ins id='NinaO'></ins><ul id='NinaO'></ul><sub id='NinaO'></sub></form><legend id='NinaO'></legend><bdo id='NinaO'><pre id='NinaO'><center id='NinaO'></center></pre></bdo></b><th id='NinaO'></th></span></q></dt></tr></i><div id='NinaO'><tfoot id='NinaO'></tfoot><dl id='NinaO'><fieldset id='NinaO'></fieldset></dl></div>
                    <tbody id='NinaO'></tbody>
                • 本文介绍了Mac 上的 iOS 7 模拟器不适用于自定义位置(也不会请求许可)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试制作一个使用设备当前位置的 iOS7 应用程序.我在我的 Mac 上使用 iPhone 模拟器,但我遇到了一些问题.每次出现位置管理器所在的视图时,它都会打印出 0.000000 的纬度和经度,即使在我设置了自定义位置(从模拟器>调试>位置)之后也是如此.

                  I'm trying to make an iOS7 app that uses the current location of the device. I'm using the iPhone simulator on my Mac, but I'm having some problems. Every time my view that the location manager is in appears, it prints out 0.000000 for both latitude and longitude, even after I've set a custom location (from simulator>debug>location).

                  此外,模拟器在打开应用程序时没有请求使用当前位置的权限似乎很奇怪.有人知道这里发生了什么吗?

                  Also, it seemed strange that the simulator didn't ask for permission to use current location when it opened the app. Anybody know what's going on here?

                  - (void)viewDidLoad
                  {
                      [super viewDidLoad];
                      // Do any additional setup after loading the view, typically from a nib.
                      [super viewDidLoad];
                      CLLocationManager *locationManager = [[CLLocationManager alloc] init];
                      locationManager.delegate = self;
                      locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
                      locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
                      [locationManager startUpdatingLocation];
                  
                      _location = [locationManager location];
                  
                  
                      _coord.longitude = _location.coordinate.longitude;
                      _coord.latitude = _location.coordinate.latitude;
                  }
                  
                  - (void)viewWillAppear:(BOOL)animated
                  {
                      [super viewWillAppear:animated];
                      _coord.longitude = _location.coordinate.longitude;
                      _coord.latitude = _location.coordinate.latitude;
                      printf("%f
                  ",self.coord.longitude);
                      printf("%f
                  ",self.coord.latitude);
                  }
                  

                  推荐答案

                  需要从委托方法didUpdateLocationToLocation:fromLocation:中获取newLocation.还要实现 didFailWithError 委托方法.您需要一些时间才能开始获取更新的位置,因此需要委托调用.

                  You need to get the newLocation from the delegate method didUpdateLocationToLocation:fromLocation:. Also implement didFailWithError delegate method. It takes some time before you start getting updated locations, hence the delegate call.

                  最后一个位置通常被缓存,因此检查位置的时间戳并将旧位置过滤掉可能是明智之举.

                  The last location is usually cached, so it maybe wise to check location's timestamp and filter the old location out.

                  这是我能提供的最简洁的例子.在 Xcode 中启动新项目,选择 Single View 应用程序模板,iPhone.不要触摸情节提要,只需用它替换 ViewController.m 的内容并在模拟器或设备中运行.如果在模拟器上,请转到调试并设置一些位置,您将在控制台中获得坐标.当视图打开或关闭屏幕时,我也会开始和停止位置更新.

                  This is the cleanest example I can provide. Start new project in Xcode, pick Single View application template, iPhone. Don't touch storyboard, just replace content of your ViewController.m with this and run in Simulator or device. If on Simulator, go to Debug and set some location and you will get coordinates in the console. I am also starting and stopping location updates when the view goes on or off screen.

                  #import "ViewController.h"
                  #import <CoreLocation/CoreLocation.h>
                  
                  @interface ViewController () <CLLocationManagerDelegate>
                  
                  @property (strong, nonatomic) CLLocationManager *locationManager;
                  
                  @end
                  
                  @implementation ViewController
                  
                  #pragma mark - Location Manager delegate methods
                  
                  - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
                  
                      if ([newLocation.timestamp timeIntervalSinceNow] >= -300.0) {
                  
                          NSLog(@"updated location with latitude %f longitude %f", newLocation.coordinate.longitude, newLocation.coordinate.latitude);
                      }
                  }
                  
                  - (void)viewWillAppear:(BOOL)animated
                  {
                      [super viewWillAppear:animated];
                  
                      [self.locationManager startUpdatingLocation];
                  }
                  
                  - (void)viewWillDisappear:(BOOL)animated
                  {
                      [super viewWillDisappear:animated];
                  
                      [self.locationManager stopUpdatingLocation];
                  }
                  
                  - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error     {
                      if(error.code == kCLErrorDenied) {
                  
                          // alert user
                          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Access to location services is disabled"
                                                                          message:@"You can turn Location Services on in Settings -> Privacy -> Location Services"
                                                                         delegate:nil
                                                                cancelButtonTitle:@"OK"
                                                                otherButtonTitles:nil];
                          [alertView show];
                  
                      } else if(error.code == kCLErrorLocationUnknown) {
                          NSLog(@"Error: location unknown");
                      } else {
                          NSLog(@"Error retrieving location");
                      }
                  }
                  
                  #pragma mark - Location Manager getter
                  
                  - (CLLocationManager *)locationManager
                  {
                      if (!_locationManager) {
                          _locationManager = [[CLLocationManager alloc] init];
                          _locationManager.delegate = self;
                          _locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
                          _locationManager.distanceFilter = 60.0;
                      }
                      return _locationManager;
                  }
                  
                  @end
                  

                  这篇关于Mac 上的 iOS 7 模拟器不适用于自定义位置(也不会请求许可)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么 CLLocationManager 在模拟器中的 iphone SDK 4 b 下一篇:使用地理位置按钮检索当前位置和邮编

                  相关文章

                  最新文章

                  <small id='fwjIw'></small><noframes id='fwjIw'>

                  <legend id='fwjIw'><style id='fwjIw'><dir id='fwjIw'><q id='fwjIw'></q></dir></style></legend>

                  • <bdo id='fwjIw'></bdo><ul id='fwjIw'></ul>

                    <i id='fwjIw'><tr id='fwjIw'><dt id='fwjIw'><q id='fwjIw'><span id='fwjIw'><b id='fwjIw'><form id='fwjIw'><ins id='fwjIw'></ins><ul id='fwjIw'></ul><sub id='fwjIw'></sub></form><legend id='fwjIw'></legend><bdo id='fwjIw'><pre id='fwjIw'><center id='fwjIw'></center></pre></bdo></b><th id='fwjIw'></th></span></q></dt></tr></i><div id='fwjIw'><tfoot id='fwjIw'></tfoot><dl id='fwjIw'><fieldset id='fwjIw'></fieldset></dl></div>

                      <tfoot id='fwjIw'></tfoot>