Why is the MKMapView userLocation property causing garbage ... for a while?

I have a map view defined in IB, and it is set to display the location of the user.

In my application, at -viewDidAppear, I request self.mapView.userLocation.location.coordinate and returns with crazy values, such as:

Latitude: 4.8194501961644877e-49
Longitude: 2.2993313035571993e-59

However, the next time -viewDidAppear is called (after I just switched to another tabbed view and then back to that), the userLocation property contains exactly the right values ​​for my current location.

It appears that the userLocation property was not initialized during my initial call, but even though I read the Apple documentation, I don’t see any caveats saying that this property only works after xxx is executed.

Is there something that needs to happen before userLocation is valid for use, or should I just use the CLLocationManager and ask it instead?

Thanks in advance for your help.

Unfortunately, Thomas's suggestion did not help. Since then I have discovered the following:

If showUserLocation is not, then userLocation is never set correctly and -MapView: didUpdateUserLocation: is never called, so I never get a reasonable location value.

, , showUserLocation YES, , , ( ), , . , , , ! , . Aaargh!

, showUserLocation YES, -MapView: didUpdateUserLocation:, , , !

+3
3

, - , .

viewDidLoad :

- (void)mapView:(MKMapView *)myMapView didUpdateUserLocation:(MKUserLocation *)userLocation;

mapview .:)

+5

Core Location. , , , - "---"...

.horizontalAccuracy , . .

+1

for didUpdateUserLocation to be called, you need to have ... mapView.showsUserLocation = TRUE;

0
source

Source: https://habr.com/ru/post/1783672/


All Articles