Search code examples
react-nativerealm

What is the most appropriate data type for latitude/longitude in Realm for React Native?


I'm trying to determine what the most optimal choice is for a Realm object schema that needs to store latitude and longitude properties.

From my understanding, the ideal data type (if I was using something like swift) would be a signed number datatype with a precision of 6.

It does not appear that the precision of the number can be controlled from React Native, which is to be expected since its mapped to a Javascript object, but it is still not clear to me as to what the appropriate choice is.

From the Realm documentation for React Native:

int, float, and double properties map to JavaScript Number objects. Internally ‘int’ and ‘double’ are stored as 64 bits while float is stored with 32 bits.

Realm Docs - Basic property types

I assume that float ist the correct choice but it's not clear to me that this is the right answer. Any thoughts from someone experienced with how realm handles these datatypes is much appreciated.


Solution

  • Float is the right choice. 32 bits are sufficient to store latitude and longitude and it will be more efficient.