I am using CLLocationManager to try and grab my users latitude and longitude, cast them into an NSString and display them on screen in a UILabel using the following code;
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D location=newLocation.coordinate;
NSString *latLong = [NSString stringWithFormat:@"%f,%f",location.latitude,location.longitude];
locationView.text = latLong;
}
Everything compiles and runs without issue, but the UILabel ‘locationView’ does not get populated. I have tested with just creating an NSString and trying that which works fine.
Any ideas where my error is?
Your
locationViewis likelynilat the time of the call. You may need to store the location in an instance variable and onviewDidLoadset thelocationViewtext there as well.