4

I have a problem that I can't solve for some time.

I have a GMSMapView with imageView in front of it in the center. In result - I can drag map and always have centered pin. But problems come when I zoom the map. On zooming - position of map target changes and my imageView points to another location.

I can detect if zoom changed, but I cant actually force GMSMapView to do ONLY zoom without any location changing.

-(void) mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position
{
    if (mZoomLevel != mapView.camera.zoom)
    {
        mZoomLevel = mapView.camera.zoom;
    }
}

So basically, I want to have always centered pin, even if I perform zoom. I tried GMSMarker - but it has problems with performance when following map center. It doesn't do it instantly, so I decided to use imageView.

Main question: how to lock current location of the map while performing zoom?

quarezz
  • 454
  • 1
  • 6
  • 11
  • Ok, so i figured out that I actually can force map to lock and stop scrolling. GMSUISettings map property has a 'scrollGestures' and 'zoomGestures' flags which might help. But I've faced another problem. I must return to GMSMarker instead of imageView because imageView still changes location on zoom(actually the map in the bg does). I can switch marker and imageView but it looks terrible. I'm trying to achieve effect of the GetTaxi iOS app. Everything is very smooth there. But still have no luck – quarezz Jan 19 '15 at 20:43

3 Answers3

8

Google fixed this issue with google maps sdk 1.10.0.

The solution is to simply add this line when configuring GMSMapview:

_mapView.settings.allowScrollGesturesDuringRotateOrZoom = NO;
UNIQL
  • 118
  • 1
  • 4
  • setting false solved my issue, Now I want to call a revere geocode service to get the address. which place is the better to call reverse geocode svc to reduce calls. Because idleAtCameraPosition delegate is calling when zoom in and out also. – siva krishna Aug 19 '16 at 13:11
  • But in my case (Maps 2.7.0) this still changes the center location :-( I cannot scroll thats true but the camera target position updates. Some way to prevent this? – blackjacx May 08 '18 at 17:32
3

Well, after 10 days of going back to this problem, I finally solved it! The answer was pretty easy!

Few steps here: 1. Add imageView as marker on top of the GMSMapView 2. Add UIPanGestureRecognizer to the GMSMapView (don't forget to set delegate, it is important) 3. Then use this code:

- (void) didPan:(UIPanGestureRecognizer*) gestureRecognizer
{
    if (gestureRecognizer.state == UIGestureRecognizerStateEnded)
    {
        _mapView.settings.scrollGestures = true;
    }
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if (gestureRecognizer.numberOfTouches > 1)
    {
        _mapView.settings.scrollGestures = false;
    }
    else
    {
        _mapView.settings.scrollGestures = true;
    }
    return true;
}
quarezz
  • 454
  • 1
  • 6
  • 11
-1

Swift 3:

mapView.settings.scrollGestures = false
Alex
  • 13
  • 6