The MKUserLocation is a class that is used to create an annotation for the users current location. This particular class is responsible for the blue dot you see on the screenshot to the left. Although I call it a blue dot, it is actually a type of annotation specifically used for the current location of the device.
The MKUserLocation class has 5 properties and no methods. The location, updating and heading property are readonly as you cannot set your location programatically, likewise you cannot update your heading programatically. The way you would set these properties is simply by pointing the phone in another direction or by walking somewhere else. The new values would then be provided to you.
The title and subtitle properties are not readonly. What this means is that you can change the text that is provided when you tap on the blue dot. By default it says “Current Location”. If you set the title and subtitle to some custom text, you can display something different if you wish.
You would do that with the following code:
self.mapView.userLocation.title = @"I'm Here"; self.mapView.userLocation.subtitle = @"Come and Find Me";
The result would be what you see to the right.
The MKUserLocation class is relatively simple. It provides you with where you are, where you are heading and lets you know if the location is being updated. Additionally, we have seen that it also allows you to set the title and subtitle of the annotation as pictured to the right.
This ends this brief tutorial. Next time, we’ll look at how you can customise the look of the MKUserLocation annotation just in case you don’t want to use the standard blue dot.