Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have a smooth animated move between 2 Google Maps locations?

Tags:

google-maps

When clicking from one marker to another in Google Maps, the map screen animates the move smoothly if both markers are within them initial map view but jumps if one of the markers is off screen.

I'm trying to set up a map which has several locations within the main map area but has one which is 'off screen'. I have a signpost icon to the more distant location within the initial map area which I want to smoothly scroll to the off screen location when clicked (so as to give a better sense of it's relative location). I can't find anything in the Maps API which would let me do this however.

I could zoom out, move and then zoom in again but this looks a bit jarring. Am I missing something in the API, or does anyone have any suggestions?

like image 318
pelms Avatar asked Jan 21 '10 10:01

pelms


People also ask

How do I move a marker smoothly on Google Maps?

The transition() and moveMarker() are used to move marker smoothly on click on the Google map.


2 Answers

Unfortunately, I don't think this is possible (without a change from Google). From the v3 API reference for panTo:

Changes the center of the map to the given LatLng. If the change is less than both the width and height of the map, the transition will be smoothly animated.

which implies that if that change is not less than the dimensions of the map, the transition won't be smoothly animated. The other pan methods are similar.

You could try moving in multiple steps but that's a bit of a hack and I suspect the result will be poor.

Sorry that's not very helpful (I have the same problem).

like image 148
Robin Minto Avatar answered Sep 20 '22 19:09

Robin Minto


For me this method works, but i'm using Google Maps API v2.

LatLng latLng = new LatLng(lat,lng); map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, ZOOM_FACTOR)); 

This animates the camera from current position to the new one.

like image 38
Alessandro Borile Avatar answered Sep 19 '22 19:09

Alessandro Borile