Dav*_*ard 9 google-maps-sdk-ios ios7 xcode5
我将浏览Google Maps SDK for iOS入门页面,了解如何在给定边界上缩放和居中视图.Build a GMSCameraPosition中提供了此代码,其中提到"移动相机有时会使整个感兴趣区域以最大可能的缩放级别可见".
此措辞类似于通过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;
}
Run Code Online (Sandbox Code Playgroud)
但是,预期结果与实际结果不符.
预期结果

实际结果
也许我对"最大可能缩放级别"的含义感到困惑.我认为它意味着尽可能紧密地放大,而不是缩小.无论哪种方式,我做错了什么或这是一个错误?
Bre*_*ett 21
以下是对代码的轻微更改,使其按预期工作:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
有关说明,请参阅viewDidLoad和viewDidAppear之间的区别.
| 归档时间: |
|
| 查看次数: |
6715 次 |
| 最近记录: |