【问题标题】:Google Maps SDK for iOS issue when rotating to landscape旋转到横向时适用于 iOS 的 Google Maps SDK 问题
【发布时间】:2014-05-23 03:45:30
【问题描述】:

我有一个来自 Google Maps SDK for iOS(最新版本)的 Google Map。我在UIScrollerView 中显示这样的地图:

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_;
    }    
}

因此,当您从 Portrait => Portrait 进入此视图时,它会起作用。 当您从 Landscape => Landscape 进入此视图时,它会起作用。

但是当您从人像 => 人像然后在视图中更改为风景时,相机不再居中。另外,当您从 Landscape => Landscape 进入此视图然后变成 Portrait 时,它可以工作。

知道如何修复肖像 => 风景问题的相机吗?

【问题讨论】:

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


    【解决方案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];        
        }
    }
    

    请注意,注释行并未修复错误。

    【讨论】:

    • 试过了,但似乎并没有解决问题。地图相机似乎仍然指向偏离中心的某个地方。界面方向更改后,地图边界似乎没有正确更新。
    • 发现问题(至少在我的情况下):需要更新到 SDK 的 1.9.0 才能在 iPhone 6/6+ 和 iOS8 上使用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-07
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多