iOS Google Map SDK:使用GMSCameraUpdate更改Google Map缩放级别:fitBounds:withEdgeInsets

时间:2016-03-22 17:08:31

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

我想使用GMSCameraUpdate:fitBounds:withEdgeInsets更改iOS Google Map SDK缩放级别。但问题是,当我使用GMSCameraUpdate:fitBounds:withEdgeInsets时,Google地图正在采用默认的缩放级别。这里使用withEdgeInsets来更改地图位置。任何帮助将不胜感激。 以下是我的完整代码。

GMSCoordinateBounds *markerBounds = [[GMSCoordinateBounds alloc] initWithPath:gmsPath];
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate fitBounds:markerBounds withEdgeInsets:UIEdgeInsetsMake(-500, 0, 0, 0)];
[mapView_ animateWithCameraUpdate:updatedCamera];

此处gmsPath包含[GMSMutablePath path]的多个坐标。

当我使用[mapView_ animateToZoom:10];时,withEdgeInsets无效。

我搜索了谷歌和stackoverflow,但我找不到正确的结果。

2 个答案:

答案 0 :(得分:0)

您可能应该调整地图大小以适应可用空间,而不是使用边缘插图来获得相同的效果。特别是,调整地图大小可确保Google徽标可见,这是使用SDK的要求。

如果您不想这样做,那么我认为您应该使用UIEdgeInsetsMake(0, 0, 500, 0)之类的东西,即底边的正插图,而不是顶边的负插入。不应硬编码500,而应使用表格的高度(以磅为单位)。

答案 1 :(得分:0)

我找到了UIEdgeInsetsMake的解决方案。以下是解决方案。

GMSCoordinateBounds *markerBounds = [[GMSCoordinateBounds alloc] initWithPath:gmsPath];
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate fitBounds:markerBounds withEdgeInsets:UIEdgeInsetsMake(44, 0, self.view.frame.size.height - 180, 0)];
[mapView_ animateWithCameraUpdate:updatedCamera];

-180是UITableView

之上的可用空间