Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>MKMapView</code> automatically places an annotation of class <code>MKUserLocation</code> when you set <code>mapView.showsUserLocation = YES</code>.</p> <p>You can replace the default view for this annotation to whatever default annotation view you want by doing this in <code>mapView:viewForAnnotation:</code>:</p> <pre><code>- (MKAnnotationView *) mapView:(MKMapView *)theMapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation { if ([annotation isKindOfClass:[MKUserLocation class]]) { // replace the following with code to generate and return custom user position annotation view return customAnnotationView; } //*** other code ***// } </code></pre> <p><em><strong>Update:</em></strong></p> <p>If all you want to do is set a pin initially (once) at the user's location when the view loads, then you will have to wait until the phone can grab the data you need since that takes some time. Add your annotation in <code>mapView:didUpdateUserLocation</code> the first time it is called, and that should do the trick:</p> <pre><code>- (void) mapView:(MKMapView *)theMapView didUpdateUserLocation:(MKUserLocation *)userLocation { static BOOL annotationAdded = NO; if (!annotationAdded) { annotationAdded = YES; //*** add annotation to mapView ***// } } </code></pre> <p><em><strong>Final Comment:</em></strong></p> <p>I would generally avoid setting a static pin at a users location the first time this method is called, however, and instead opt to just using the default standard blue dot. That is because the location services in the phone take time to find an accurate reading on the user's location, but in the interest of time it will send you location updates as soon as possible. This means that the first location update may not be very accurate, but subsequent updates may be much more accurate. That is why the standard blue dot sometimes changes position frequently within the first few moments of showing up on the map.</p> <p>Just a caveat. Obviously what you choose to do depends on what the purpose of your app is.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload