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

后端 未结 8 922
伪装坚强ぢ
伪装坚强ぢ 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 13:09

    Try this in

    CLLocation *userLoc = mapView.userLocation.location;
    CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
    
    NSLog(@"user latitude = %f",userCoordinate.latitude);
    NSLog(@"user longitude = %f",userCoordinate.longitude);
    

    ViewdidAppear: or call perform seletor after delay

    0 讨论(0)
  • 2020-12-03 13:11

    From the document on CLLocation, if the horizontal accuracy or vertical accuracy is negative, it means it can't find a value. I suspect that's what is happening here. Bear in mind that if you just look once, it may give you an approximate last known location before ever improving the accuracy result.

    Horizontal Accuracy The coordinate’s latitude and longitude identify the center of the circle and this value indicates the radius of that circle. A negative value indicates that the coordinate’s latitude and longitude are invalid.

    0 讨论(0)
提交回复
热议问题