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

后端 未结 8 1020
伪装坚强ぢ
伪装坚强ぢ 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:56

    If you try to get user co-ordinates in viewDidLoad() method, it will always give 0,0 result, because it is not yet initialized.

    You should take a look at "Where Am I" sample code form Apple site. It explains what you need. You need to use CLLocationManager class. You will also need the method

    *-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation*
    

    This method will be called automatically every time when user location is updated. If you are using simulator, then this method will be called only once and it will return some default co-ordinates.

    Hope it helps.

提交回复
热议问题