Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pros & Cons of Using animateToRegion() vs animateCamera()

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?

like image 828
AndrewTelkamp Avatar asked Jun 06 '19 00:06

AndrewTelkamp


People also ask

What do pros mean?

noun, plural pros. a proponent of an issue; a person who upholds the affirmative in a debate. an argument, consideration, vote, etc., for something.

What pros and cons mean?

The pros and cons of something are its advantages and disadvantages, which you consider carefully so that you can make a sensible decision. They sat for hours debating the pros and cons of setting up their own firm. Motherhood has both its pros and cons.

How do spell pros?

Pros is the plural form of pro, which may mean a professional, someone who is extremely proficient in something. Pro may also mean to be in favor of something or an argument in favor of something.

Does Pro mean advantage?

pro noun [C] (ADVANTAGE)an advantage to or a reason for doing something: One of the big pros of living in Madrid is the night life. You have to weigh all the pros and cons of the matter before you make a decision.


1 Answers

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

like image 123
Chris Poe Avatar answered Sep 21 '22 22:09

Chris Poe