Check if user location is visible on map iphone

拥有回忆 提交于 2019-12-04 05:37:04

If you want to know whether the user location is contained in the currently displayed map region, you can check the userLocationVisible property in the regionDidChangeAnimated delegate method:

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

If you just want to know whether the user location currently has a value (whether it's visible or not and whether showsUserLocation is on 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)"):

There is property called userLocationVisible.

In Apple Docs

A Boolean value indicating whether the device’s current location is visible in the map view. (read-only)

if user location is not visible you does not get current lat,long . put the condition if lat ,long == 0. then button hide or show. it work on only device(gps)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!