Fixed
Status Update
Comments
jo...@jonshier.com <jo...@jonshier.com> #2
Actually, a multiplier of 8.67 gets me back to the approximate position it should be.
br...@google.com <br...@google.com>
br...@google.com <br...@google.com> #3
This bug was fixed in 2.1.1. Thanks for the report!
jo...@jonshier.com <jo...@jonshier.com> #4
While the behavior has changed, it is still incorrect, IIUC. Now the view is shifted up too much for the values entered. For instance, when I enter a bottom inset of 200, which is less than half of the total height (509) of the map, and so should have no effect on the default centering behavior, the marker is actually centered at 354.5 points from the bottom, which is the center of the map plus half of the bottom inset. This seems incorrect per my understanding of that API.
fu...@gmail.com <fu...@gmail.com> #5
354.5 sounds exactly right to me.
Description
Here's the code I think should work:
func animateMap(centeringOn coordinate: CLLocationCoordinate2D, bottomOffset: CGFloat? = nil) {
let previousMaxZoom = mapView.maxZoom
mapView.setMinZoom(mapView.minZoom, maxZoom: 17)
let coordinateBounds = GMSCoordinateBounds(coordinate: coordinate, coordinate: coordinate)
let bottomInset = (mapView.bounds.size.height - fabs(bottomOffset ?? 0)) / 2.0 + fabs(bottomOffset ?? 0)
let insets = UIEdgeInsets(top: 0, left: 0, bottom: bottomInset, right: 0)
let cameraUpdate = GMSCameraUpdate.fit(coordinateBounds, with: insets)
mapView.animate(with: cameraUpdate)
mapView.setMinZoom(mapView.minZoom, maxZoom: previousMaxZoom)
}
The calculation of the bottom inset should be correct, as the bottomOffset passed in is the height of the info view. From what I can tell, this offset should be enough to push the marker up so it appears centered in the remaining view. e.g. A mapView height of 509 and a bottomOffset of 190 gives me a remaining view height of 319, half of which added to the bottomOffset is 349.5. If the marker was inset this much from the bottom of the view, it would appear centered in the visible map area. However, what I see is that the marker is only moved a fraction of that distance and appears only slightly above center. Bizarrely, multiplying the bottom of the UIEdgeInsets by 7.5 gets me an approximately correct value. I've tried a variety of ways of accomplishing this, but nothing seems to work correctly.
Operating system version: 10.0/10.1
Google Maps SDK for iOS version: 2.1.0
Hardware model: Simulator
*********************************************************
For developers viewing this issue: please click the 'star' icon to be
notified of future changes, and to let us know how many of you are
interested in seeing it resolved.
*********************************************************