我有一个问题,我认为这很简单……我已经使用 mapkit 编写了一个应用程序,并使用没有 GPS 的模拟器在我的 Mac 上进行了开发。因此,我是否对坐标进行硬编码以模拟用户位置。今天,当我第一次在我的 iPhone 上尝试我的应用程序时,我认为我只需要稍微更改我的代码即可从 GPS 读取坐标并获取有关用户位置的信息。但它并没有那么容易。有谁知道如何解决这个问题?我需要用户经度和纬度来计算到另一个位置的距离,我想我可以做这样的事情......?
CLLocationManager *clm = [[CLLocationManager alloc]init];
[clm.delegate self];
[clm startUpdatingLocation];
userLocationFromGPS = clm.location.coordinate;
//the userLocationFromGPS is a CLLocationCoordinate2D userLocationFromGPS object
user = [[Annotations alloc]initWithCoordinate:userLocationFromGPS];
[user setTheTitle:@"You are here!"];
userLocationPlain =
[[CLLocation alloc]initWithLatitude:userLocationFromGPS.latitude longitude:userLocationFromGPS.longitude];
我需要坐标,但不知道如何获得它们……有什么想法吗?提前致谢!