我的应用在模拟器上运行得非常完美,一切正常。但现在我想在我的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
每次在 iPhone 上运行应用程序时,lat1 和 lat2 的值都为 0。但是在模拟器上却可以正常工作。
有人知道这是为什么吗?