0

I have a MapView and marked where the user's location and nearby there are other annotationView of various types regarding tourist attractions. I want the MapView is scrollable and zoomable to see all annotationView of the city, but when I move the MapView returns immediately centered shooting, ugly looking.

this is the code in MapViewController.m

 - (void)viewDidLoad{

        //.....

   self.mapView.zoomEnabled=YES;
   self.mapView.scrollEnabled = YES;

      //......
  }


 - (void) locationManager:(CLLocationManager *) manager
 didUpdateToLocation:(CLLocation *) newLocation
        fromLocation:(CLLocation *) oldLocation {

      //......
  self.coordinate = CLLocationCoordinate2DMake(self.latitudine, self.longitudine);
  CLLocationCoordinate2D min = CLLocationCoordinate2DMake(self.coordinate.latitude -0.005,
       self.coordinate.longitude-0.005);

 CLLocationCoordinate2D max = CLLocationCoordinate2DMake(self.coordinate.latitude+0.005,
       self.coordinate.longitude+0.005);

 CLLocationCoordinate2D center = CLLocationCoordinate2DMake((max.latitude + min.latitude)
       / 2.0, (max.longitude + min.longitude) / 2.0);
 MKCoordinateSpan span = MKCoordinateSpanMake(max.latitude - min.latitude, max.longitude -
      min.longitude);
 MKCoordinateRegion region = MKCoordinateRegionMake(center, span);

 self.mapView.region= region;

  [mapView setRegion:region animated:TRUE];

     //......

 }
Ortensia C.
  • 4,666
  • 11
  • 43
  • 70

2 Answers2

2

I think it is because the update is getting called constantly, so it will center the screen all the time with your mapview setregion bit.

When you declared your locationManager bet sure to set the sensitivity.

self.locationManager.distanceFilter = 10.0f;

This will only call the update if it changes more than 10 meters.

mashdup
  • 875
  • 7
  • 18
0

Everytime the device notices it has changed location, you are zooming the map to self.latitudine and self.longitudine. In the code you have shown you are not setting those values to anything new. Do you mean to be zooming in on the newLocation coordinates?

Craig
  • 8,093
  • 8
  • 42
  • 74