1

I'm looking to achieve the same zoom as Uber and Lyft does.

When pinch to zoom I'd like to keep the map centered. I was able to do the double tap centered, but not the pinch, after some research those topics not helped :

First Second

Any sample code or advices for this kind of feature ?

Community
  • 1
  • 1
agonist_
  • 4,890
  • 6
  • 32
  • 55
  • Sorry friend can't go to the map screens of uber and lfyt app. if you can provide any video. then maybe i could help you. – Mustanser Iqbal Dec 23 '15 at 21:56
  • I linked those topic in my question and its not really helping me. The pinch is not complete – agonist_ Dec 24 '15 at 00:01
  • 1
    @Daniel Nugent- you reported the post as duplicate , have you tried the link which you have provided , it does not work , please make Stackoverflow a nice community where people help each other and save others time – Naga Mar 22 '16 at 13:38
  • @Daniel Nugent, I really tried the code and I modified as well but it was not working marker was still getting misplaced, but the question is how uber is doing this – Naga Mar 22 '16 at 14:41
  • I have answered here. https://stackoverflow.com/a/57461453/9273416 Feedback is much appreciated. – Sai Karthik Aug 12 '19 at 15:50

1 Answers1

-1

You will have to handle the Google Maps zoom_changedevent and set the center to the original center whenever this event is fired

 map.addListener('zoom_changed', function() {
        map.setCenter(center);
    });

Further, this will stop the user from panning the map and then zooming again. If the user pans the map and then zooms it, the map will be reset to center which you might not want. However if the user does not zoom, he/she can normally pan through the map. You may want to clear this event listener for certain cases.

See a codePen here

PS: Use http only and not https while checking this codepen. I spent almost half an hour trying to get this work in JSfiddle but couldn't.

ihimv
  • 1,308
  • 12
  • 25