Note that there are some explanatory texts on larger screens.

plurals
  1. POTurning user location annotation with heading
    text
    copied!<p>I'm trying to change the User Annotation in my app so that it shows the usual blue dot, but with a triangle coming off of it to show which direction the user is facing (I'd rather rotate the user annotation than the entire map, which is what MKUserTrackingModeFollowWithHeading does). I've got a rudimentary version working, but it has some weird behavior.</p> <p>First, some code:</p> <pre><code>-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id&lt;MKAnnotation&gt;)annotation { if ([annotation isKindOfClass:[MKUserLocation class]]) { _userLocationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"userLocationIdentifier"]; //use a custom image for the user annotation _userLocationView.image = [UIImage imageNamed:@"userLocationCompass.png"]; return _userLocationView; } else { return nil; } } -(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { //rotate user location annotation based on heading from location manager. if (!_locatorButton.hidden) { CLLocationDirection direction = newHeading.magneticHeading; CGAffineTransform transform = CGAffineTransformMakeRotation(degreesToRadians(direction)); _userLocationView.transform = transform; } } -(void)GPSButtonPressed:(id)sender { if (self.GPSEnabled) { //if GPS is already on, disable it. _mapview.showsUserLocation = NO; [_mapview removeAnnotation:_mapview.userLocation]; self.GPSEnabled = NO; [_locationManager stopUpdatingHeading]; } else { //enable GPS. _mapview.showsUserLocation = YES; self.GPSEnabled = YES; if ([CLLocationManager headingAvailable]) { [_locationManager startUpdatingHeading]; } } } </code></pre> <p>The user location annotation image shows up fine, and rotates based on the heading, but here are the funny behaviors:</p> <p>1- The annotation does not follow my location-- it only stays in one place, but rotates with the correct heading. If I turn off the GPS with the "GPS Button", then turn it back on, the annotation shows up in the correct place, but still won't follow as I walk.</p> <p>2- If I scroll the map, the annotation pops back to due north, then quickly rotates to the correct heading, causing an annoying flickering effect.</p> <p>3- If I turn off the GPS and remove the user location, the annotation is removed as intended, but if I then scroll the map, the annotation pops back to the screen rather than staying hidden.</p> <p>What am I doing wrong? Thanks for any helpful hints!</p>
 

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