CLLocation *userLoc = mapView.userLocation.location;
CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
NSLog(@"user latitude = %f",userCoordinate.latitude);
NSLog(@"user longitude = %f",userCoordinate.longitude);
mapView.delegate=self;
What does the above code do all in all? no need for a line by line explanation as I understand the lingo.. just unsure of what this code is used for..
First, you should learn how to dig through apple docs to answer these type of questions. I usually start by searching for XXX class reference or XXX developer guide.
mapview is an MKMapView object. See here: http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html
userLocation returns the user’s current location. From those docs:
The code then gets the coordinates of the user location and logs out the latitude and longitude.
Finally, setting the delegate to self means this class will implement the callbacks of the MKMapViewDelegate protocol. From those docs:
See here for what a delegate is: What exactly does delegate do in xcode ios project?
So the callbacks allow you to interject code into the pipeline execution of the map view and to also provide data like viewForAnnotation.
And here is the docs on the MKMapVeiwDelegate (the callbacks for you mapview):
http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intf/MKMapViewDelegate