开发者

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

When clicking from one marker to another in Google Maps, 开发者_如何学Cthe 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?


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


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.


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 :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜