gpt4 book ai didi

ios - 如何在iOS中使用模拟器进行GPS坐标调试?

转载 作者:可可西里 更新时间:2023-11-01 05:20:40 24 4
gpt4 key购买 nike

我尝试获取我所在位置的坐标。

我用 stackoverflow,所以我的代码如下:

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

CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];

self.longitude=coordinate.longitude;
self.latitude=coordinate.latitude;

NSLog(@"dLongitude : %f",self.longitude);
NSLog(@"dLatitude : %f", self.latitude);

但我总是得到 0。上面的代码错了吗?或者我没有为 GPS 位置设置我的模拟器?

我不明白为什么我在获取坐标时遇到问题。

最佳答案

首先,您的代码中存在几个问题:

  1. 你应该在某个地方保留 locationManager 以保持它的运行
  2. 实现 -locationManager:didUpdateLocations:-locationManager:didFailWithError: 委托(delegate)方法
  3. 此外,如果您使用的是 iOS 8,则应添加 [locationMamager requestWhenInUseAuthorization];[locationMamager requestAlwaysAuthorization];
  4. 在您的 Info.plist 中相应地指定 NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription

可以用Xcode模拟定位,看苹果的资料:https://developer.apple.com/library/ios/recipes/xcode_help-debugger/articles/simulating_locations.html

关于ios - 如何在iOS中使用模拟器进行GPS坐标调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29004280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com