Check if the user's location is displayed on the iphone map

I want to hide or show the current location of the UIButton weather user, which is visible on the map. When testing xcode, I can see the meassage "User location view is NOT visible but should be. Showing...." on the console in the "didUpdateLocation" method if the users location is not displayed on the map. How can I use this message to generate events in my case to hide or show UIButton? Thanks for any help in advance.

+6
source share
3 answers

If you want to find out if the user's location is in the currently displayed area of ​​the map, you can check the userLocationVisible property in the delegate method regionDidChangeAnimated :

 - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { someButton.hidden = !mapView.userLocationVisible; } 

If you just want to find out if the user’s location is currently located (whether it is visible or not, and whether showUserLocation is showing or not), then:

 if (mapView.userLocation.location == nil) NSLog(@"user location not obtained yet"); else NSLog(@"user location available (may or may not be currently visible)"): 
+11
source

There is a property called userLocationVisible.

At Apple Docs

A boolean value indicating whether the current location of devices is visible on the map. (Only for reading)

+4
source

If the user's location is not displayed, you are not getting the current lat, long. set the condition if lat, long == 0. then click hide or show. it only works on the device (gps)

+1
source

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


All Articles