我正在开发适用于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_;
当我运行时,我的标记和折线都显示在正确的位置,但地图缩小到它可以到达的最大距离(尽管它在路径上居中)。有什么建议吗?
答案 0 :(得分:2)
此代码是loadView
吗?尝试在loadView
中创建地图视图,但稍后更新相机,可能在viewDidLoad
或viewWillAppear
。
根据这个问题的答案,我认为相机更新方法可能无法正常使用loadView
: