0

我有一个地图视图,它设置为放大用户当前位置。问题是,如果用户在查看地图时更改了位置,它会放大回当前位置。这使我无法将功能用于我计划做的事情。我将在地图上有多个图钉,但如果位置发生变化,用户将无法查看所有图钉。即使我的设备放在我的桌子上,位置也会不断变化,因此地图会不断地将用户从他们正在查看的地图的任何部分带回到他们当前位置的缩放视图。有人对此有任何想法吗?

- (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];
}
4

3 回答 3

2

问题是这些行:

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[worldView setRegion:region animated:YES];

也就是说,将视图缩放回用户的位置,缩放系数为250,250. 因此,如果您不希望在用户移动视图后缩小视图,请不要这样做!

于 2013-05-03T23:01:25.723 回答
0

我们可以第一次停止接收当前位置,

- (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;
}
于 2013-05-04T02:02:19.273 回答
0

使用 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)

}
于 2015-09-19T13:11:03.120 回答