4

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 ?

Community
  • 1
  • 1
mfahem
  • 69
  • 6

2 Answers2

5

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

Andrew Walz
  • 890
  • 2
  • 8
  • 27
  • 1
    I already tried that which was the answer in the link I posted but it did not work. The map is still moving when I zoom in or out :-( – mfahem Jun 29 '16 at 10:39
-1

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));
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
  • 1
    You are showing me to Android stuff but my problem is in iOS (in swift). Also when I talk about zooming in or out I'm talking about a manual zoom not a zoom done programmatically. When a user double taps on the screen, the zoom is made but the center of the screen is not on the same position he was in prior to the zoom. – mfahem Jun 30 '16 at 10:42