Ios GMSCameraUpdate缩小到最大距离,而不是围绕路径

Ios GMSCameraUpdate缩小到最大距离,而不是围绕路径,ios,google-maps,google-maps-sdk-ios,Ios,Google Maps,Google Maps Sdk Ios,我正在为iOS开发一个应用程序,我在使用谷歌地图sdk时遇到了一些问题 我的应用程序获得一个坐标列表,并在它们之间绘制一条多段线以及开始和结束标记。目前,这一切都成功地实现了。我现在要做的是更新相机以包含整个路径。这是我目前的代码: GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[[sharedModel startNode] nodeLocation].latitude

我正在为iOS开发一个应用程序,我在使用谷歌地图sdk时遇到了一些问题

我的应用程序获得一个坐标列表,并在它们之间绘制一条多段线以及开始和结束标记。目前,这一切都成功地实现了。我现在要做的是更新相机以包含整个路径。这是我目前的代码:

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[[sharedModel startNode] nodeLocation].latitude
                                                        longitude:[[sharedModel startNode] nodeLocation].longitude
                                                             zoom:18];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];

GMSMutablePath *path = [GMSMutablePath path];
for (int i = 0; i < [results count]; i++)
{
    [path addCoordinate:[[results objectAtIndex:i] nodeLocation]];
}
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeWidth = 10;
polyline.map = mapView_;

GMSMarker *marker1 = [[GMSMarker alloc] init];
marker1 = [GMSMarker markerWithPosition:[[results objectAtIndex:0] nodeLocation]];//[[sharedModel startNode] nodeLocation]];
marker1.title = @"Start";
marker1.map = mapView_;

GMSMarker *marker2 = [[GMSMarker alloc] init];
marker2 = [GMSMarker markerWithPosition:[[results lastObject] nodeLocation]];
marker2.title = @"Finish";
marker2.map = mapView_;

GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithPath:path];

GMSCameraUpdate *update = [GMSCameraUpdate fitBounds:bounds];

[mapView_ moveCamera:update];
self.view = mapView_;
GMSCameraPosition*camera=[GMSCameraPosition cameraWithLatitude:[sharedModel startNode]节点位置].latitude
经度:[[sharedModel startNode]节点位置]。经度
缩放:18];
地图视图=[GMSMapView地图WithFrame:CGRectZero相机:相机];
GMSMutablePath*path=[GMSMutablePath];
对于(int i=0;i<[结果计数];i++)
{
[路径添加坐标:[[结果对象索引:i]节点位置]];
}
GMSPolyline*polyline=[GMSPolyline polylineWithPath:path];
折线.strokeWidth=10;
polyline.map=mapView;
GMSMarker*marker1=[[GMSMarker alloc]init];
marker1=[GMSMarker markerWithPosition:[[results objectAtIndex:0]节点位置]]//[[sharedModel startNode]节点位置]];
marker1.title=@“开始”;
marker1.map=mapView;
GMSMarker*marker2=[[GMSMarker alloc]init];
marker2=[GMSMarker markerWithPosition:[[results lastObject]nodeLocation]];
marker2.title=@“完成”;
marker2.map=mapView;
GMSCoordinateBounds*bounds=[[GMSCoordinateBounds alloc]initWithPath:path];
GMSCameraUpdate*update=[GMSCameraUpdate fitbunds:bounds];
[地图视图\移动摄影机:更新];
self.view=mapView;

当我运行此操作时,我的标记和多段线都显示在正确的位置,但地图会缩小到它可以达到的最大距离(尽管它位于路径的中心)。有什么建议吗?

此代码是否在
loadView
中?尝试在
loadView
中创建地图视图,但稍后更新相机,可能在
viewdiload
视图中出现

根据对这个问题的回答,我认为可能在
loadView
中摄像头更新方法无法正常工作:


代码都在loadView中。我尝试将相机更新部分移动到viewDidLoad,但仍然得到相同的结果,但如果将更新部分移动到VIEWWILLEASE,它似乎可以工作。这似乎很奇怪,为什么它只能在那里工作,但至少现在可以了。谢谢