How can I change the filling of the GMSMapView without moving the map

I would like to be able to change the filling of the GMSMapView without changing the location of the map. Currently, the Google Maps iOS SDK is changing the location of the map, so that the same point is in the center after adding the add-on. This is different from how the Android SDK works, which just leaves the card as it is.

I found a small workaround for this, but it does not work sequentially. I can calculate what should be for the new center location, and update the map camera when I change the gasket as follows ...

UIEdgeInsets oldPadding = self.mapCtrl.map.padding; UIEdgeInsets newPadding = UIEdgeInsetsMake(top, left, bottom, right); float deltaX = ((newPadding.right - newPadding.left)/2 - (oldPadding.right-oldPadding.left)/2); float deltaY = ((newPadding.top - newPadding.bottom)/2 - (oldPadding.top-oldPadding.bottom)/2); GMSCameraUpdate *updatedCamera = [GMSCameraUpdate scrollByX:deltaX Y:deltaY]; [self.mapCtrl.map setPadding:newPadding]; [self.mapCtrl.map moveCamera:updatedCamera]; 

But I would say that it only works at 50%. The remaining 50% of the card is moved to a new place of filling, and then back to where I want.

I see two possible solutions for this: A) change the gasket in another way so that it does not move the card, or B) figure out a way to make the above code work somehow to pause or group card movements so that both calls go through at once. But I can’t figure out how to do either of these two things.

+9
source share
2 answers

Make sure you have the same addition above and below so that everything is kept in the center.

+1
source

If someone needs this in the future:

 mapView.padding = newPadding mapView.layer.removeAllAnimations() 

This is a GMSMapView internal elements of the GMSMapView and padding does not apply correctly to the map itself, only to the user interface.

I use the following code to reapply the indent after my animation so that the map works correctly again.

 let newCenter = mapView.projection.coordinate(for: mapView.bounds.inset(by: newMapViewPadding).center) mapView.padding = newMapViewPadding + UIEdgeInsets(all: 1) mapView.padding = newMapViewPadding mapView.moveCamera(GMSCameraUpdate.setTarget(newCenter)) 
0
source

All Articles