2014-05-22 147 views
1

我從Google Maps SDK for iOS(最新版本)中獲得Google Map。我在UIScrollerView顯示的地圖是這樣的:旋轉到橫向時的Google Maps SDK for iOS問題

showMarker = YES; 
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[geocodeLatitude floatValue] longitude:[geocodeLongitude floatValue] zoom:13]; 
[self setupMapWithCamera:camera withLatitude:geocodeLatitude withLongitude:geocodeLongitude]; 

float mapHeight = 50; 
[mapView_ setFrame:CGRectMake(0, 0, widthOfBlock, mapHeight)]; 
[self.scroller addSubview:mapView_]; 

調用的方法是:

-(void)setupMapWithCamera:(GMSCameraPosition *)camera withLatitude:(NSString *)Slatitude withLongitude:(NSString *)Slongitude { 
    // setup map 
    [mapView_ clear]; 
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    mapView_.settings.scrollGestures = NO; 
    mapView_.settings.zoomGestures = NO; 

    // setup marker 
    if (geocodesuccess || showMarker) { 
     GMSMarker *marker = [[GMSMarker alloc] init]; 
     marker.position = CLLocationCoordinate2DMake([Slatitude floatValue], [Slongitude floatValue]); 
     if ([ShopWithDatas.open isEqualToString:@"1"] || [ShopWithDatas.open2424 isEqualToString:@"1"]) { 
      marker.icon = [GMSMarker markerImageWithColor:[UIColor greenColor]]; 
     } else { 
      marker.icon = [GMSMarker markerImageWithColor:[UIColor redColor]]; 
     } 
     [mapView_ setSelectedMarker:marker]; 
     marker.map = mapView_; 
    }  
} 

所以,當你從人像=>人像這一觀點進入它的工作原理。 從Landscape => Landscape進入此視圖時,它將起作用。

但是,當您從縱向=>縱向,然後在視圖中切換到橫向時,相機不再居中。另外,當你從風景=>風景進入這個視圖,然後變成肖像時,它就起作用。

任何想法如何修復相機的肖像=>景觀問題?

回答

1

最後,即使我不明白爲什麼它不正確地更新,我發現這個解決方案:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    if (canIshowMap) { 
     CLLocationCoordinate2D actualLocation = CLLocationCoordinate2DMake([geocodeLatitude floatValue], [geocodeLongitude floatValue]); 
     GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:actualLocation]; 
     [mapView_ moveCamera:updatedCamera]; 
     //[mapView_ animateToLocation:actualLocation];   
    } 
} 

請注意,註釋行不修復的bug。

+0

試過這個,但它似乎並沒有解決這個問題。地圖相機似乎仍指向偏離中心的某個地方。在界面方向更改後,似乎地圖邊界沒有正確更新。 – StephenT

+0

發現問題(至少在我的情況下):需要更新到SDK的1.9.0以用於iPhone 6/6 +和iOS8 – StephenT