Transform Annotationview based on the direction of the title of the user's location

I am trying to convert an annotation based on the direction of the user's location. View designation does not change as expected.

LocationMapView.userTrackingMode=YES;

locationManager.headingFilter =5;

[locationManager startUpdatingLocation];

[locationManager startUpdatingHeading];


(void) calculateUserAngle:(CLLocationCoordinate2D)current {
  double x = 0, y = 0 , deg = 0,delLon = 0;

  float fixLon=current.longitude;
  float fixLat=current.latitude;

  delLon = fixLon - current.longitude;
  y = sin(delLon) * cos(fixLat);
  x = cos(current.latitude) * sin(fixLat) - sin(current.latitude) * cos(fixLat) * cos(delLon);
  deg = RADIANS_TO_DEGREES(atan2(y, x));

  if(deg<0){
      deg = -deg;
  } else {
      deg = 360 - deg;
  }
  degrees = deg;
}


(void)locationManager:(CLLocationManager *)manager  didUpdateLocations:(NSArray *)locations{
    newLocation = [locations lastObject];
    NSLog(@"DidUpdateLocation--%f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude);
    CLLocationCoordinate2D here =  newLocation.coordinate;
    [self calculateUserAngle:here];
}

(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
annotationView.transform = CGAffineTransformMakeRotation((degrees-newHeading.trueHeading) * M_PI / 180);
}

      

+3


source to share





All Articles