【问题标题】:fitBounds in GoogleMaps SDK for ios does not fit适用于 ios 的 GoogleMaps SDK 中的 fitBounds 不适合
【发布时间】:2014-01-02 04:30:30
【问题描述】:

我想在 GoogleMaps for 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;

【问题讨论】:

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


    【解决方案1】:

    此代码在loadViewviewDidLoad 中吗?基于这些较早的问题,我认为相机更新只能从viewWillAppear 正常工作:

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

    Fit bounds not working as expected

    【讨论】:

    • 感谢您的回答。我已尝试将此代码添加到您提到的每个方法(loadView、viewDidLoad 和 viewWillAppear)中。问题还是一样。
    • 嗨,马丁,你能发布你的完整代码吗?我认为您需要在viewDidLoad 中创建地图视图,然后在viewWillAppear 中设置相机位置。
    猜你喜欢
    • 2015-04-29
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多