gpt4 book ai didi

ios7 - 拟合边界未按预期工作

转载 作者:行者123 更新时间:2023-12-02 14:29:00 26 4
gpt4 key购买 nike

我正在浏览 Google Maps SDK for iOS Getting Started页面以了解如何在给定范围内缩放和居中 View 。 Build a GMSCameraPosition 中提供了此代码。 ,其中提到“有时移动相机很有用,以便在最大可能的缩放级别下可以看到整个感兴趣的区域。”

这个写法是similar to another possible approach via a GMSCameraUpdate ,“返回一个 GMSCameraUpdate,它会转换相机,使指定的边界以最大可能的缩放级别在屏幕上居中。”

下面的代码直接取自入门页面中的两个链接——稍作修改以提供有意义的屏幕截图;调整对实际结果没有影响。

- (void)loadView
{
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;

CLLocationCoordinate2D vancouver = CLLocationCoordinate2DMake(49.26, -123.11);
CLLocationCoordinate2D calgary = CLLocationCoordinate2DMake(51.05, -114.05);

GMSMarker *vancouverMarker = [[GMSMarker alloc] init];
vancouverMarker.position = vancouver;
vancouverMarker.title = @"Vancouver";
vancouverMarker.map = mapView_;

GMSMarker *calgaryMarker = [[GMSMarker alloc] init];
calgaryMarker.position = calgary;
calgaryMarker.title = @"Calgary";
calgaryMarker.map = mapView_;

GMSCoordinateBounds *bounds =
[[GMSCoordinateBounds alloc] initWithCoordinate:vancouver coordinate:calgary];

[mapView_ moveCamera:[GMSCameraUpdate fitBounds:bounds]];
//These last two lines are expected to give the same result as the above line
//camera = [mapView_ cameraForBounds:bounds insets:UIEdgeInsetsZero];
//mapView_.camera = camera;
}

但是,预期结果与实际结果不符。

预期结果
expected

实际结果
actual

也许我对“最大可能的缩放级别”的含义感到困惑。我认为这意味着尽可能放大,而不是缩小。不管怎样,我做错了什么还是这是一个错误?

最佳答案

这里对您的代码进行了一些细微的更改,使其按预期工作:

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;

CLLocationCoordinate2D vancouver = CLLocationCoordinate2DMake(49.26, -123.11);
CLLocationCoordinate2D calgary = CLLocationCoordinate2DMake(51.05, -114.05);

GMSMarker *vancouverMarker = [[GMSMarker alloc] init];
vancouverMarker.position = vancouver;
vancouverMarker.title = @"Vancouver";
vancouverMarker.map = mapView_;

GMSMarker *calgaryMarker = [[GMSMarker alloc] init];
calgaryMarker.position = calgary;
calgaryMarker.title = @"Calgary";
calgaryMarker.map = mapView_;

GMSCoordinateBounds *bounds =
[[GMSCoordinateBounds alloc] initWithCoordinate:vancouver coordinate:calgary];

[mapView_ moveCamera:[GMSCameraUpdate fitBounds:bounds]];
//These last two lines are expected to give the same result as the above line
//camera = [mapView_ cameraForBounds:bounds insets:UIEdgeInsetsZero];
//mapView_.camera = camera;
}

参见Difference between viewDidLoad and viewDidAppear以获得解释。

关于ios7 - 拟合边界未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19576117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com