GoogleMaps SDK for ios中的fitBounds不适合

时间:2013-12-14 11:45:29

标签: ios objective-c google-maps-sdk-ios

我想在GoogleMaps中为ios SDK使用fitBounds方法并且视图不适合。我的变量很好(路径,数组等等),因为我可以在地图上看到带有标记的折线。唯一不起作用的是适合观看。哪里弄错了?谢谢。

// Create a 'normal' polyline.
GMSPolyline *polyline = [[GMSPolyline alloc] init];
GMSMutablePath *path = [GMSMutablePath path];

locationInfoArray = [LocationInfoMemoryManager loadLocationDataWithPath:_locationInfoPathString];

for (int i=0; i<locationInfoArray.count; i++) {
    LocationInfo* locationInfo = locationInfoArray[i];
    CLLocationCoordinate2D locationPoint = {locationInfo.latitude, locationInfo.longitude};
    [path addCoordinate:locationPoint];
}


GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[locationInfoArray[0] latitude]
                                                        longitude:[locationInfoArray[0] longitude]
                                                             zoom:5 ];


mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

polyline.path = path;
polyline.strokeColor = [UIColor blueColor];
polyline.strokeWidth = 10.f;
polyline.zIndex = 15;  // above the larger geodesic line
polyline.map = mapView;

GMSMarker *startMarker = [[GMSMarker alloc] init];
startMarker.title = @"Start";
startMarker.snippet = @"Info will be here";
startMarker.position = CLLocationCoordinate2DMake([[locationInfoArray firstObject] latitude], [[locationInfoArray firstObject] longitude]);
startMarker.map = mapView;
startMarker.flat = NO;
//sydneyMarker.rotation = 30.0;
mapView.selectedMarker = startMarker;

GMSMarker *finishMarker = [[GMSMarker alloc] init];
finishMarker.title = @"Finish";
finishMarker.snippet = @"Info will be here";
finishMarker.position = CLLocationCoordinate2DMake([[locationInfoArray lastObject] latitude], [[locationInfoArray lastObject] longitude]);
finishMarker.map = mapView;
finishMarker.flat = NO;
mapView.selectedMarker = finishMarker;

//Here is probably problem

GMSCoordinateBounds *bounds; = [[GMSCoordinateBounds alloc] initWithPath:path];
GMSCameraUpdate *update = [GMSCameraUpdate fitBounds:bounds withPadding:20];
[mapView moveCamera:update];

self.view = mapView;

1 个答案:

答案 0 :(得分:3)

此代码是loadView还是viewDidLoad?基于这些早期的问题,我认为相机更新只能在viewWillAppear

中正常运行

GMSCameraUpdate zooming out to the max distance rather than around a path

Fit bounds not working as expected