2017-03-28 67 views
0

我基本上實現了一個功能,其中在用戶移動地圖後出現一個按鈕,並且當選擇該按鈕時,在可見區域中發生新的搜索。問題是可見區域不準確,所以當我嘗試再次放大時,它會縮小。在iOS上的谷歌地圖上設置位置

每當我點擊按鈕時,下面的函數被調用,地圖縮小。據我所知,沒有要求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) 

回答

0

你必須設置縮放級別到你想要什麼,當你撥打GMSCameraPosition.camera,例如:

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

參見:https://developers.google.com/maps/documentation/ios-sdk/views#using_gmscameraupdate

參見標題爲攝像機位置

「地圖視圖被建模爲相機向下看在平坦面上。相機的位置(以及地圖的渲染)由以下屬性指定:緯度/經度位置,縮放,方位和視角。「

+0

這不起作用我想因爲我不知道縮放級別,我知道邊界,API返回邊界,我需要正確顯示邊界 – aryaxt

+0

因此,只需決定任意縮放級別,並將其保持在該縮放級別,以便在更新時不會縮小。 –

+0

如果它需要顯示整個內容,它不應該縮放: – aryaxt