-5
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..

bryanmac
  • 38,941
  • 11
  • 91
  • 99
Simagen
  • 409
  • 2
  • 8
  • 18

1 Answers1

1

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:

userLocation
The annotation object representing the user’s current location. (read-only)

@property(nonatomic, readonly) MKUserLocation *userLocation

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:

delegate
The receiver’s delegate.

@property(nonatomic, assign) id<MKMapViewDelegate> delegate
Discussion
A map view sends messages to its delegate regarding the loading of map data and changes in     the portion of the map being displayed. The delegate also manages the annotation views used to highlight points of interest on the map.

The delegate should implement the methods of the MKMapViewDelegate protocol.

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

Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99