【问题标题】:How to get current longitude and latitude in xcode simulator? [duplicate]如何在 xcode 模拟器中获取当前的经度和纬度? [复制]
【发布时间】:2013-04-11 12:38:23
【问题描述】:

我正在尝试按位置获取当前的经纬度,但我得到的都是 0.0000,我正在使用以下代码

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

    return coordinate;
}

并称之为使用:

CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];

NSLog(@"*dLatitude : %@", latitude);
NSLog(@"*dLongitude : %@",longitude);

我还在项目中添加了核心定位。 请给我建议。

【问题讨论】:

标签: iphone xcode


【解决方案1】:

实现位置管理器的委托方法

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

您可以使用 newLocation.coordinate.latitude 和 newLocation.coordinate.longitude 获取 lat 和 lng

对于在模拟器中设置当前位置,您可以关注@ios_av

【讨论】:

    【解决方案2】:

    您必须使用此路径添加自定义位置: 选择 iPhone Simulator 并在菜单中选择Debug -->Loction --> Custom Location

    【讨论】:

      【解决方案3】:

      IPHone 模拟器总是给出 0.0000 的纬度和经度,因为它没有检测到位置。

      您可以使用此路径添加自定义位置: 选择 iPhone Simulator 并选择 Debug -->Location --> Custom Location

      【讨论】:

        【解决方案4】:

        试试这个

        1. 在 iPhone 模拟器中运行项目
        2. 在 TextEdit 文件中创建以下文件,例如命名为 MyOffice。将扩展名设为 .gpx
        3. 在Xcode的Simulate区域选择Add GPX File to Project...
        4. 将创建的文件从菜单添加到项目。
        5. 现在您可以在模拟区域看到您的位置:

        【讨论】:

        • 我做了上面的步骤,但是我的位置是空的,坐标是0.00000。
        【解决方案5】:

        模拟器不能返回当前位置,它给出了默认的加利福尼亚纬度和经度位置,但是你可以通过-调试->位置->自定义位置在模拟器中设置静态位置

        【讨论】:

        • 我无法在 xcode 中找到调试-> 位置-> 自定义位置,
        • 首先点击模拟器设备,当模拟器出现时,工具栏上方会显示一些选项,如iossimulator,文件,编辑,硬件,调试,窗口,帮助,您将点击调试和继续你的过程。
        • Adnan 是否有效?
        • 我确实定义了,但它仍然给我 long 和 lat 0.0000 但 getlocation 返回 null。你能帮我返回正确的位置吗?
        【解决方案6】:

        在模拟器中,您可以强制一个本地位置:转到 menu:debug:position 并选择一种声音(有些通过预先注册的路线模拟移动)或输入您选择的坐标

        【讨论】:

          【解决方案7】:

          如果您想在应用中获取当前位置,请查看本教程
          http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_Location_Application

          如果您没有在设备上运行它,请为模拟器添加纬度和经度
          为此检查此
          https://stackoverflow.com/a/12637537/2106973

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-06-05
            • 2017-07-23
            • 1970-01-01
            • 2019-10-11
            • 2011-08-31
            • 2020-10-10
            相关资源
            最近更新 更多