将GMSMapView限制为某些边界

时间:2018-01-07 15:43:24

标签: ios swift google-maps

我有两个坐标,我需要将我的Google地图地图限制为由这两个坐标限定的框架。例如,我有

SELECT SANKEY_NODE.TYPE_DETAIL_ID FROM SANKEY_NODE AS n

然后,我写,

let bounds = GMSCoordinateBounds(
    coordinate: CLLocationCoordinate2D(
        latitude: 59.615440364671244, 
        longitude: -17.978949286043644
    ), coordinate: CLLocationCoordinate2D(
        latitude: 33.963318167747758, 
        longitude: 21.442294009029865
    )
)

然而,这并没有限制地图的界限。根据文件,

  

如果不是nil,[cameraTargetBounds]约束相机目标,以便手势不会导致它离开指定的边界。

This question对我没有帮助,部分是因为我必须允许缩放和平移 - 它必须限制在某个区域。

为什么这不起作用,我该如何解决?

1 个答案:

答案 0 :(得分:0)

您必须使用 GoogleFletcher 。在这里,我们将实现两个过滤器(GMSCoordinateBound和Type)。在开始边界坐标中,我们将放置当前位置,而在结束边界中,我们只需在当前位置坐标中添加1。 希望它会有所帮助。

let location = locations.last!
let neBoundsCorner = CLLocationCoordinate2D(latitude:location.coordinate.latitude,
                   longitude: location.coordinate.longitude)
let swBoundsCorner = CLLocationCoordinate2D(latitude: location.coordinate.latitude + 1, longitude: location.coordinate.longitude + 1)
let bounds = GMSCoordinateBounds(coordinate: neBoundsCorner,coordinate: swBoundsCorner)
let filter = GMSAutocompleteFilter()
    filter.type = .establishment 
    fetcher = GMSAutocompleteFetcher(bounds: bounds, filter: filter)