You have two bad habits.
- You should not depend on the simulator in situations requiring the status of a hardware censor. Especially if you need the right test.
- You are not handling types correctly. Therefore, you cannot check the values correctly. How
-1067024384 ? The value of longitude is degrees. This means that the valid range is limited to -90.0 ~ +90.0 by definition of longitude.
Your longitude value is out of range. This means one of them. You printed the value incorrectly or the actual value was incorrect. The simulator may print the wrong value. Or you printed the value with the wrong method. You must try:
Test on a real device with real hardware censors.
If after that a bad result occurs,
View ALL of your application code. Especially for printing, processing values. Make sure you use the right types and castings in every situation. Because you can work with the error somewhere usually.
In addition, I recommend checking all intermediate values like this.
CLLocationCoordinate2D annocoord = annotation.coordinate; CLLocationCoordinate2D usercoord = self.mapView.userLocation.coordinate; NSLog(@"ANNO = %f, %f", annocoord.latitude, annocoord.longitude); NSLog(@"USER = %f, %f", usercoord.latitude, usercoord.longitude); CLLocation *loc = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude]; CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:self.mapView.userLocation.coordinate.latitude longitude:self.mapView.userLocation.coordinate.longitude]; NSLog(@"LOC = %f, %f", loc.coordinate.latitude, loc.coordinate.longitude); NSLog(@"LOC2 = %f, %f", loc2.coordinate.latitude, loc2.coordinate.longitude); CLLocationDistance dist = [loc distanceFromLocation:loc2]; NSLog(@"DIST: %f", dist);
source share