Pros & Cons of Using animateToRegion() vs animateCamera()
Asked Answered
B

1

8

Building out react-native-maps and trying to decide the pros and cons of using animateToRegion vs. animateCamera. In the past we've handled everything on a region basis.

Seems like region would be a better choice, as you won't have to worry about differences between elevation and zoom, while also having a more granular control of the exact region being displayed if needed.

Anyone have any thoughts or experiences that have led them to one or the other?

Bunyan answered 6/6, 2019 at 0:1 Comment(0)
B
5

I just made this switch myself. I found that animateCamera() is more versatile and allows for cleaner syntax.

The biggest pro for animateCamera() is that you can do multiple animations from a single method call.

An example of centering to coords and turning the camera 180 degrees with animateCamera():

this.map.animateCamera({
  center: {
    latitude: 0,
    longitude: 0,
  },
  heading: 180,
});

If you wanted to do the same thing with animateToRegion() you would need to call two methods:

this.map.animateToRegion({
  latitude: 0,
  longitude: 0,
});
this.map.animateCamera({
  heading: 180,
});

Not as clean.

As of right now, a con for animateCamera() is that you don't seem to be able to pass a latitudeDelta and longitudeDelta into the center property like you can with region, specified here.

In short, if you don't need to use a latitudeDelta and longitudeDelta then animateCamera() is the way to go. If I had to speculate, I would say animateToRegion() is going to be deprecated like the other methods sometime in the future in favor of animateCamera().

Bays answered 14/6, 2019 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.