我正在开发适用于 iOS 的应用程序,但在使用 google maps 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_;
当我运行它时,我的标记和折线都显示在正确的位置,但地图被缩小到它可以走的最大距离(尽管它位于路径的中心)。有什么建议吗?