iPhone current user location coordinates showing as (0,0)

后端 未结 8 1049
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 12:28

I\'m trying to get the users current latitude and longitude with this viewDidLoad method. The resulting map is correctly indicating the current location however the NSLog c

8条回答
  •  盖世英雄少女心
    2020-12-03 12:53

    As Kendall said, the MKMapView does not have a user location until it finishes loading, and the viewDidLoad method is usually too early to request it. A simpler way than using CoreLocation is to implement the MKMapViewDelegate method -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation. It will give you the user's location as soon as it is located, without having to deal with a CLLocationManager.

提交回复
热议问题