Reputation: 3600
I have a map view and it is set to zoom in on the users current location. The problem is that if the user changes location when looking at the map, it zooms back into the current location. It's making it impossible to use the functionality for what I'm planning to do. I'm going to have multiple pins on the map but the user won't be able to look at all of them if the location is changing. Even when my device is sitting on my desk, the location keeps changing slightly so the map is constantly taking the user from whatever part of the map they are viewing back to a zoomed view of their current location. Does anyone have any ideas on this?
- (void)foundLocation:(CLLocation *)loc
{
CLLocationCoordinate2D coord = [loc coordinate];
// Zoom the region to this location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 250, 250);
[worldView setRegion:region animated:YES];
[activityIndicator stopAnimating];
[locationManager stopUpdatingLocation];
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[worldView setRegion:region animated:YES];
}
Upvotes: 0
Views: 3736
Reputation: 2555
Zoom in to current location with Swift:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
let region : MKCoordinateRegion = MKCoordinateRegionMakeWithDistance(locValue, 250,250)
self.mapView.setRegion(region, animated: true)
}
Upvotes: 0
Reputation: 9040
We can stop receiving current location for the first time,
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[worldView setRegion:region animated:YES];
[locationManager stopUpdatingLocation];
locationManager.delegate = nil;
}
Upvotes: 0
Reputation: 535889
The problem is these lines:
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[worldView setRegion:region animated:YES];
That is you, zooming the view back to the user's location with a zoom factor of 250,250
. So if you don't want the view to be zoomed back after the user moves it, don't do that!
Upvotes: 2