【发布时间】:2013-03-08 19:08:48
【问题描述】:
我的应用在模拟器上运行完美,一切正常。但是现在我想在我的 iPhone 上使用它,我发现 GPS 功能不起作用。
这是我的代码。
[super viewDidLoad];
//eigener Standort
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
eigLat = newLocation.coordinate.latitude;
eigLon = newLocation.coordinate.longitude;
eigLatString = [NSString stringWithFormat:@"%f", eigLat];
eigLonString = [NSString stringWithFormat:@"%f", eigLon];
}
到目前为止,一切都很好。如果我使用 NSLog,我会得到正确的坐标。
但是我想在这里使用我的坐标:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
news = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:NULL];
for (x=0; x<[news count]; x++)
{
//Berechnung der Entfernung
erdradius = 6371.1;
//Koordinaten von Datenbank in String schreiben
NSString *latitude = [[news objectAtIndex:x] objectForKey:@"Latitude"];
NSString *longitude = [[news objectAtIndex:x] objectForKey:@"Longitude"];
entfernung = 0;
double lat1 = eigLat; //eigener Standort Latitude
double long1 = eigLon; //eigener Standort Longitude
double lat2 = [latitude doubleValue]; //Standort Heurigen Latitude
double long2 = [longitude doubleValue]; //Standort Heurigen Longitude
在那里,lat1 和 lat2 每次都得到 0。但前提是我在 iPhone 上运行应用程序。在模拟器上运行良好。
有人知道为什么会这样吗?
【问题讨论】:
-
eigLat 在哪里定义? (不是 GPS 问题,是简单的编程问题,在 didUpdateToLocation 中记录输出 eigLat,在手机上也可以。)
-
在.h文件中作为double
-
为什么将数字存储为字符串?在
connectionDidFinishLoading:中,data从何而来? -
@Sebastian 这不是重点,问题是 lat1 / eigLat 为 0; (字符串来自 JSON)
-
数据来自我的 JSON;我认为它更容易,因为我得到字符串,然后将其转换为双精度
标签: iphone cocoa-touch gps ios-simulator