当前位置: 首页 > 知识库问答 >
问题:

在iOS模拟器上使用CLLocationManager查找纬度和经度[重复]

拓拔谭三
2023-03-14

我试图创建一个使用MKMapView打开地图的应用程序,然后通过创建CLLocationManger的委托来查找用户的当前位置。

我已经在下面发布了我的代码。我现在遇到的问题是,尽管打开模拟器时地图确实出现,但它没有从NSLog中给出一个应该经过纬度和经度的位置或新的航向。

我是Objective-C和应用程序开发的新手,有人看到我是否遗漏了ClLocationManager的一些协议吗?谢谢你的帮助。

对不起,代码有点草率,很快就贴进去了。

  #import "ViewController.h"
  #import <MapKit/MapKit.h>
  #import <CoreLocation/CoreLocation.h>

  @interface ViewController () <CLLocationManagerDelegate>
  @property (nonatomic,strong)CLLocationManager * myLocationManger;
  @property (nonatomic,strong) IBOutlet MKMapView *myMapView;
  @end

  @implementation ViewController

  - (void)viewDidLoad {
      [super viewDidLoad];
      NSLog(@"insdie view did load");

     //    Setting the map to be big as the view
      self.myMapView =[[MKMapView alloc]init];

//Initial Property to Map
     self.myMapView =[[MKMapView alloc] init];

//Set type to Standard
self.myMapView.mapType = MKMapTypeStandard;

//Set Mask for AutoReszing
self.myMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth |                                              UIViewAutoresizingFlexibleHeight;

//Add the View!
[self.view addSubview:self.myMapView];

///*Now lets Use my CLLocation Manager to Locate the iPhone's Posistion*////



//Chekcs if Location Services are Enabled
if ([CLLocationManager locationServicesEnabled]) {
    self.myLocationManger = [[CLLocationManager alloc] init];
    self.myLocationManger.delegate = self;

    [self.myLocationManger startUpdatingLocation];



}
else{
    //Location Services are available we will need software to ask to turn this On
    //The user is SOL if they refuse to turn on Location Services
    NSLog(@"Location Services not enabled");


}



}

  -(void)locationManager:(CLLocationManager *)manager
      didUpdateToLocation:(CLLocation *)newLocation
      fromLocation:(CLLocation *)oldLocation
  {
      //This method will show us that we recieved the new location
      NSLog(@"Latitude = %f",newLocation.coordinate.latitude );
      NSLog(@"Longitude =%f",newLocation.coordinate.longitude);

  }

  -(void)locationManager:(CLLocationManager *)manager
   didFinishDeferredUpdatesWithError:(NSError *)error{
      NSLog(@"Error with Updating");
  }



  -(void)locationManager:(CLLocationManager *)manager
  didFailWithError:(NSError *)error
  {
//Failed to recieve user's location
NSLog(@"failed to recived user's locatio");
  }

共有1个答案

郗学
2023-03-14

我发现在新的iOS8中,您需要将两个键添加到Plist。这篇文章很好地解释了这个过程。

http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/

 类似资料:
  • 问题内容: 我想使用Swift获取位置的当前经度和纬度,并通过标签显示它们。我尝试执行此操作,但标签上没有任何显示。 问题答案: 恕我直言,当您寻找的解决方案非常简单时,您就使代码复杂化了。 我已经通过使用以下代码来做到这一点: 首先创建和请求授权的实例 然后检查用户是否允许授权。 用它来做到这一点 您将它们设置为的想法是正确的,但是我能想到的唯一原因是用户未给予您许可,这就是为什么您当前的位置数

  • 我正在尝试检索我的地理位置的最新长使用一个谷歌API。此api接受蜂窝塔信息。尽管我提供了所有的信息,但在很长一段时间内,我都没有得到正确的信息。 https://developers.google.com/maps/documentation/geolocation/intro 有人用这个API找到lat long吗?GoogleGEO定位API的精确度有多高?

  • 问题内容: 我正在编写一个小程序,为了提高效率,我需要能够找到数组中最接近的纬度和经度。 假设您有以下代码: 我得到的结果是: 它应该是(在此示例中,列表中的最后一个对象) 我知道如何获取单个值的最接近单元格,但我想让lambda函数考虑这两个值,但我不确定如何做到。救命? 问题答案: 为了正确计算地球上各点之间的距离,您需要使用Haversine公式。使用此答案中提供的Python实现,您可以像

  • 问题内容: 在询问具体的代码示例之前,我只想问一下是否可以进行类似此伪代码的查询: 从表中选择项目,其中经度/经度=-在某个经度/经度点的x英里内- 那可行吗?还是我必须跳过一些箍?可以推荐的任何好的方法都很棒! 问题答案: 您应该搜索Haversine公式,但是一个好的开始可能是: 使用PHP,MySQL和Google Maps创建商店定位器 -请参见“使用MySQL查找位置”部分 使用MySQ

  • 本文向大家介绍使用Google Maps和PHP查找PostCode或ZipCode的经度和纬度,包括了使用Google Maps和PHP查找PostCode或ZipCode的经度和纬度的使用技巧和注意事项,需要的朋友参考一下 从PostCode转换为映射参考远非准确,但可以使用Google Maps API来完成。尽管每天您的请求数量受到一定限制,但您只需要询问即可从Google获得Google

  • 问题内容: 嗨,我有下表 现在我想获得两点之间的距离。假设一个用户有一个城市3,一个用户有一个城市7。我的情况是一个用户有一个城市和纬度,纬度正在搜索其他用户与城市的距离。例如,拥有城市3的用户正在搜索。他想得到其他城市的用户的距离是7。我已搜索到以下查询 据我所知,此查询查找从一个点到所有其他点的距离。现在我想获得一个点到另一点的距离。 任何指导方针将不胜感激。 问题答案: 我认为您的问题是您具