如何在xcode模拟器中获取当前的经度和纬度? [英] How to get current longitude and latitude in xcode simulator?

查看:86
本文介绍了如何在xcode模拟器中获取当前的经度和纬度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to get current long and lat by location but i am getting both 0.0000, the following code i am using

(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);

我还向该项目添加了corelocation.请告诉我.

i also added corelocation to the project. please advise me.

推荐答案

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

Implement delegate method of location manager

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

,您可以使用 newLocation.coordinate.latitude newLocation.coordinate.longitude

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

And for set current location in simulator you can follow @ios_av

这篇关于如何在xcode模拟器中获取当前的经度和纬度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆