tags:

views:

383

answers:

2

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?

+1  A: 

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).

Robin M
Yes, the result of using multiple steps or writing your own pan is poor. What tends to go wrong is that either you end up panning faster than the tiles can be fetched, which leaves you pointlessly panning over blank greyness, or you have to pan much more slowly than panTo() does when in range, which means that it takes an unacceptably long time when there's a significant distance to be panned.NOTE: multiple calls to .panTo() do not queue. The second call interrupts any pan that's currently in progress anbd replaces it.
Mike Williams
Yep, tried multiple scrolls and didn't look too good. In the end I settled for zooming out and then panning once the other marker was on screen. Doesn't look *too* bad (http://tinyurl.com/ye46vy5) and works better than a sudden jump.
pelms
A: 

If you are using Gmaps API V2, then you can implement smooth animated move very easily by using panBy() method. You have to use fromLatLngToContainerPixel() method to find the amount of pixels to pan by.

Here is the bit of code:

var newLoc = map.fromLatLngToContainerPixel(new GLatLng(lat, lng));
map.panBy(new GSize( newLoc.x, newLoc.y ));

However, what I am trying to do is to achieve the same thing in maps API V3, but sadly fromLatLngToContainerPixel() method does not work anymore the way it did :(

salman