我有两个坐标,我需要将我的Google地图地图限制为由这两个坐标限定的框架。例如,我有
let bounds = GMSCoordinateBounds(
coordinate: CLLocationCoordinate2D(
latitude: 59.615440364671244,
longitude: -17.978949286043644
), coordinate: CLLocationCoordinate2D(
latitude: 33.963318167747758,
longitude: 21.442294009029865
)
)
然后,我写,
map.cameraTargetBounds = bounds
但是,这不会限制地图的边界。根据文件,
如果不是nil,[cameraTargetBounds]约束相机目标,以便手势不会使其离开指定的边界。
This question没有帮助我,部分是因为我必须允许缩放和平移 - 它必须限制在某个区域。
为什么这不起作用,我该如何解决?
你必须使用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)