0

I've implemented - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { method to change the default location of userLocation Annotation. Inside this method I've used:

if (annotation==(mapView.userLocation)) {
    MKAnnotationView *myAnotation = [[MKAnnotationView alloc] init];

    myAnotation.image = self.userPointImage.image; 
    myAnotation.centerOffset = CGPointMake(0, 250);

    return myAnotation;
}
else
{
    return nil;
}

Which successfully moves the default userLocation annotation to center bottom. But as I'm also using heading so when move my phone it is still rotating the map from center.

- (void)locationManager:(CLLocationManager *) manager didUpdateHeading:(CLHeading *) newHeading {

    [self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:true];
}

But the userLocation annotation is below. So how to do that?

UPDATE

I found this question and tried applying it. But as I'm using heading so it crashes the app. In my didUpdateUserLocation method I added [self moveCenterByOffset:CGPointMake(0, 200) from:userLocation.coordinate]; and this method is as follows:

- (CLLocationCoordinate2D)moveCenterByOffset:(CGPoint)offset from:(CLLocationCoordinate2D)coordinate
{
    CGPoint point = [self.mapView convertCoordinate:coordinate toPointToView:self.mapView];
    point.x += offset.x;
    point.y += offset.y;
    CLLocationCoordinate2D center = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];
    return center;
}

and then in my didUpdateUserLocation method I updated it as: MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([self moveCenterByOffset:CGPointMake(0, -250) from:userLocation.coordinate], 800.0f, 200.0f); and [mapView setRegion:region animated:NO]; as I'm using heading so animation is set to NO. But now as I run the code it starts jerking between center and the new point.

Community
  • 1
  • 1
Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116

1 Answers1

1

MKCoordinateRegion region = mapClinicsView.region;

set 'region.center' It will helps you to navigate your map center position

make sure 'region.center' and annotation center latitute and longitute is same

Vivek Gajbe
  • 411
  • 2
  • 14
  • Hey I think I got your point and it can be successful. See the update portion of my question. It's now jerking between two points. It's like it sets the point below and then again animate it to center. – Chaudhry Talha Jul 20 '16 at 13:25