2
我想在GoogleMaps for ios SDK中使用fitBounds方法,並且視圖不適合。我的可變參數都是正確的(路徑,數組等),因爲我可以在地圖上看到帶有標記的折線。唯一不起作用的是適合查看。我犯了什麼錯誤?謝謝。GoogleMaps SDK for iOS中的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;
謝謝您的回答。我試圖將這個代碼添加到你提到的每個文件(loadView,viewDidLoad和viewWillAppear)。問題仍然是一樣的。 – martin
嗨馬丁,你可以發佈你的完整代碼不工作(即包括方法本身),相機更新在'viewWillAppear'?我認爲你需要在'viewDidLoad'中創建地圖視圖,然後在'viewWillAppear'中設置攝像機的位置。 –
非常感謝,它的工作原理;) – martin