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

前端 未结 3 1873
梦谈多话
梦谈多话 2021-01-31 17:41

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 marke

相关标签:
3条回答
  • 2021-01-31 18:14

    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 讨论(0)
  • 2021-01-31 18:29

    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.

    0 讨论(0)
  • 2021-01-31 18:35

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

    0 讨论(0)
提交回复
热议问题