问题
I am currently building an iOS app in swift. I put a GMSMapView inside one of my ViewControllers and I put a marker in the middle of the screen. The marker never moves.
When I zoom or unzoom, the marker position changes and so does the address associated to the marker. I want to be able to zoom on the same exact position as it is done on the Uber app.
I've read some of the answers on stackoverflow like this one : Google Maps Center while zooming but none of them worked.
Is there a way to do this directly with the Google maps SDK or should I write an algorithm that saves the last known position and zooms on this position ?
回答1:
If I understand correctly, you are looking to centre in the middle of the screen, then zoom in and out, but not have the mapview scroll?
Google maps does have this feature. To prevent the mapview from scrolling, implement allowScrollGesturesDuringRotateOrZoom = false for your mapview.settings:
myMapView.settings.allowScrollGesturesDuringRotateOrZoom = false
https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_u_i_settings.html#a4c1156d319c0724284062167e47decc4
回答2:
You cannot animate two things like zoom in and go to my location in one google map. You would do them sequentially. Move the camer first then animate the camera, though both could be animateCamera()
calls. Whether GoogleMap
consolidates these into a single event.
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(MOUNTAIN_VIEW) // Sets the center of the map to Mountain View
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
来源:https://stackoverflow.com/questions/38087475/zoom-in-the-center-of-the-screen-google-maps-ios-sdk-swift