Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS上的Google地图上设置位置_Ios_Google Maps - Fatal编程技术网

在iOS上的Google地图上设置位置

在iOS上的Google地图上设置位置,ios,google-maps,Ios,Google Maps,我基本上实现了一个功能,在用户移动地图后,会出现一个按钮,当按钮被选中时,会在可见区域进行新的搜索。问题是可见区域不准确,所以当我再次尝试放大时,它会缩小 每次我点击按钮,下面的函数就会被调用,地图就会缩小。我知道不调用animate并删除代码可以避免缩放,但我想知道为什么会发生缩放,因为这可能会在其他地方造成问题 @IBAction func updateSearchSelected(sender: UIButton) { let northEast = CLLocationCoord

我基本上实现了一个功能,在用户移动地图后,会出现一个按钮,当按钮被选中时,会在可见区域进行新的搜索。问题是可见区域不准确,所以当我再次尝试放大时,它会缩小

每次我点击按钮,下面的函数就会被调用,地图就会缩小。我知道不调用
animate
并删除代码可以避免缩放,但我想知道为什么会发生缩放,因为这可能会在其他地方造成问题

@IBAction func updateSearchSelected(sender: UIButton) {
    let northEast = CLLocationCoordinate2D(latitude: mapView!.projection.visibleRegion().farRight.latitude, longitude: mapView!.projection.visibleRegion().farRight.longitude)
    let southWest = CLLocationCoordinate2D(latitude: mapView!.projection.visibleRegion().nearLeft.latitude, longitude: mapView!.projection.visibleRegion().nearLeft.longitude)
    print("northEast \(northEast)")
    print("southWest \(southWest)")
    let coordinateBounds = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)
    let cameraUpdate = GMSCameraUpdate.fit(coordinateBounds)
    mapView?.animate(with: cameraUpdate)
}
以下是单击按钮3次后的日志

northEast CLLocationCoordinate2D(latitude: 37.84227633765466, longitude: -122.38477706909181)
southWest CLLocationCoordinate2D(latitude: 37.674750313908689, longitude: -122.50391006469727)

northEast CLLocationCoordinate2D(latitude: 37.859492217765393, longitude: -122.37251903861761)
southWest CLLocationCoordinate2D(latitude: 37.657491381296779, longitude: -122.51616809517145)

northEast CLLocationCoordinate2D(latitude: 37.880245733530728, longitude: -122.35773839056492)
southWest CLLocationCoordinate2D(latitude: 37.636675535472314, longitude: -122.53094874322414)

当调用
GMSCameraPosition.camera
时,必须将缩放级别设置为所需的级别,例如:

let camera = GMSCameraPosition.camera(withLatitude: -33.8683,
                                      longitude: 151.2086,
                                      zoom: 16)
见:

请参阅标题为“摄影机位置”的部分:


“地图视图被建模为在平面上俯视的摄影机。摄影机的位置(以及地图的渲染)由以下属性指定:纬度/经度位置、缩放、方位和视角。”

我认为这不起作用,因为我不知道缩放级别,我知道边界。API返回边界,我需要正确显示边界。只需确定任意缩放级别,并将其保持在该缩放级别,以便在更新时不会缩小。如果需要显示整个内容,它也应该缩放:(